sandy1028 Posted December 6, 2007 Share Posted December 6, 2007 Hi, The below code is fetch the data from table. The problem is for each id execw is 4 to 5 rows. But only one value is fetched. How to push all the rows into array $records. $result = mysql_query("select id,state,subtime from table1 where id="23" order by subtime desc"); $no_of_rows = mysql_num_rows($result); while($r = mysql_fetch_array($result)){ $exec = ''; $res = mysql_query("select execw from table2 where id='".$r[0]."'"); if($row = mysql_fetch_array($res)){ $exec = $row[0]; } array_push($records, "$r[0]#$r[1]#$r[2]#$r[3]#$r[4]#--#--#$exec"); } Quote Link to comment Share on other sites More sharing options...
Barand Posted December 6, 2007 Share Posted December 6, 2007 Change "if" to "while" and move the array_push() inside that loop. Quote Link to comment Share on other sites More sharing options...
sandy1028 Posted December 6, 2007 Author Share Posted December 6, 2007 SELECT t1.id, t1.state, t1.subtime, t2.execw FROM table1 t1 INNER JOIN table2 t2 ON t1.id = t2.id WHERE t1.id = 23 ORDER BY t1.subtime DESC I used the joins. But still was not able to fetch all the rows for execw. Quote Link to comment Share on other sites More sharing options...
Barand Posted December 6, 2007 Share Posted December 6, 2007 <?php $sql = "SELECT t1.id, t1.state, t1.subtime, t2.execw FROM table1 t1 INNER JOIN table2 t2 ON t1.id = t2.id WHERE t1.id = 23 ORDER BY t1.subtime DESC"; $res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); $records = array(); while ($row = mysql_fetch_row($res)) { $records[] = $row; } // check echo '<pre>', print_r($records, true), '</pre>'; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.