Mysql error echoing the variable

I have a mysql query as below -

    $id_order_last="15";
    $id_order[]=array();
    $sql1="SELECT * FROM `ps_orders` WHERE `id_order`> 
    $id_order_last  order by `id_order`";
    echo $sql1;
    $result1= mysql_query($sql1);
    $cnt=1;
    while ($row = mysql_fetch_array($result1))
    {
        /*$id_order[$i]=$row['$id_order'];*/
        echo $row['$id_order']."<br />";
        $cnt++;
        echo $cnt."<br />";
}

As you can see i have the $id_order_last set 15 so it displaying the value as 15 when echoed. To check sql i echoed it and it display

SELECT * FROM `ps_orders` WHERE `id_order`> 15 order by `id_order`

So i get in the sql, run in phpmyadmin and the tuples which get returns was correct value. It show the good result means 17 and 18 which were in database. Which means the query is correct!

then it echoed 2 and 3 the cnt++ value while $row['$id_order'] is still empty only <br /> is shown up as space.

THough i also tried the for loop to print the whole things but it still not showing up?

$i=1;
for($i;$i<=$cnt;$i++)
{
    echo $id_order_last."<br />";
    echo $id_order[$i]."<br />";
    $id_order_last=$id_order[$i];
}

Answers


use echo $row['id_order'] in place of echo $row['$id_order']

remove $.

Replace $row['$id_order'] to $row['id_order']

$id_order_last="15";
$sql1="SELECT * FROM `ps_orders` WHERE `id_order`> 
$id_order_last  order by `id_order`";
echo $sql1;
$result1= mysql_query($sql1);
$cnt=1;
while ($row = mysql_fetch_array($result1))
{
    $id_order[]=$row['id_order'];
    echo $row['id_order']."<br />";
    $cnt++;
    echo $cnt."<br />";
}

echo "<pre />";
print_r($id_order);

Need Your Help

Batch - edit specified line in text file

batch-file replace text-files edit

For example, line number 2 reads: "0" (without quotes). I want to change that 0 to a 1, without changing anything else in the text file.

cannot upload a file in javascript using php

php javascript html ajax file

I am trying to upload a file using php. But the following error is generated. Error: A problem occurred during file upload! . I am using ubuntu OS. I think the error is generated while trying to save

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.