php - Why returns the first element of an array only? -



php - Why returns the first element of an array only? -

$count =0; $result1 = mysql_query("select fwid sbsw fword = '".$searchtext."'"); while ($result2= mysql_fetch_array($result1)) { $result3 = mysql_query("select fsyn wrsyn fwid = '".$result2[$count]."'"); $result4= mysql_fetch_array($result3); print $result4[$count].'<br>'; $count++; } mysql_free_result($result1); mysql_free_result($result3);

let's have @ how mysql_fetch_array works - illustration if have table construction like

id | name | surname | role 1 john smith user 2 peter qeep user 3 mark ziii admin

when execute query select * table , loop $result = mysql_fetch_array($query), $result array(4) containing

[0] => id, [1] => name, [2] => surname, [3] => role

therefore, when execute query $result3 = mysql_query("select fsyn wrsyn fwid = '".$result2[$count]."'");, in first iteration, $count 0 key result returned previous query, in farther iteration increment , lead undefined key. means have stop using variable $count , utilize $result2[0] instead. also, way improve approach using mysql join, in illustration select w.fsyn sbsw s bring together wrsyn w on s.fwid = w.fwid s.fword = "'.$searchtext.'";

php mysql

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -