0
<?php
        session_start();
        include("dbconnect.php");
        $sql="select * from $_POST[select_catalog_query]";
        $rslt=mysql_query($sql);


        if(!mysql_fetch_array($rslt))
        {
            echo "<script type='text/javascript'>\n";
            echo "alert('There is No Data');\n";
            echo "</script>";
            echo "<script>document.location.href='admin.php'</script>";

        }
        while($row = mysql_fetch_array($rslt))
        {
            echo "<tr>";
            echo "<td>$row[id]</td>";
            $sql1 = "select * from login WHERE id=$row[id]";
            $rs = mysql_query($sql1);
            $rw1 = mysql_fetch_array($rs);
            echo "<td>$row[firstName]</td>";
            echo "<td>$row[lastName]</td>";
            echo "<td>$row[gender]</td>";
            echo "<td>$row[phone]</td>";
            echo "<td>$row[email]</td>";
            echo "<td>$rw1[type]</td>";
            echo "<td>$rw1[status]</td>";
            echo "</tr>";
        }
?>

i have 3 data in my 1st table...bt in output it's showing only 2 data...the last inserted data is not showing. What is it's solution? And in while loop when i am executing 2nd query for login table, a warning is given like this mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\myfile\as1\selectAdmin.php on line 41
how do i execute 2nd query??

Vipin Kumar KM
  • 365
  • 5
  • 16
saddam hossain
  • 57
  • 1
  • 2
  • 9

4 Answers4

0

You don't need to run multiple queries here. If you do, the time to run will increase with every new row you have in the table $_POST[select_catalog_query] by a constant factor, which is bad because this will become very inefficient for large datasets.

Instead use the following query:

SELECT * FROM tableName t1 LEFT JOIN login t2 WHERE t2.id = t1.id

This way you'll only ever need to execute 1 query.

Matt Harrison
  • 13,001
  • 6
  • 46
  • 64
0
$sql="
select
  c.*,
  l.*
FROM
  $_POST[select_catalog_query] as c
 LEFT JOIN
 login as l
WHERE
 l.id = c.id";

 $rslt=mysql_query($sql);       


 if(mysql_num_rows($rslt)==0)
 {
        echo "<script type='text/javascript'>\n";
        echo "alert('There is No Data');\n";
        echo "</script>";
        echo "<script>document.location.href='admin.php'</script>";

}
else
{
    while($row = mysql_fetch_array($rslt))
    {
       /*YOUR data*/
    }
}
0

SELECT * FROM table INNER JOIN table2 ON table.ID=table2.ID;

in this when both id will become same then it will fetch all the data

chirag
  • 103
  • 1
  • 3
  • 10
-1

here you said required 1 as parameter it means mysql_fetch_array is getting null as parameter you should check database also

and your question is not clear ask properly

id=$row[id] should be id=$row['id'] try it now

chirag
  • 103
  • 1
  • 3
  • 10