Jump to content

Arrays


sandy1028

Recommended Posts

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");
             }

Link to comment
https://forums.phpfreaks.com/topic/80416-arrays/
Share on other sites

<?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>';
?>

Link to comment
https://forums.phpfreaks.com/topic/80416-arrays/#findComment-408208
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.