Jump to content

php mysql query with two conditions problem?


shams

Recommended Posts

My web pages are organized in two mysql tables, table category with two columns cat_id and category and table subcategory with three columns cat_id, subcategory and subcat2,  i run this msyql query from terminal it is working:

mysql> SELECT subcat2 from subcategory  WHERE cat_id=1 AND subcategory=3;
+--------------+
| subcat2      |
+--------------+
| 001_003.html |
+--------------+
1 row in set (0.01 sec)

Next, i execute the dd-mysqli.php it successfully get the sql query values from the drop down menu and parse to the chgoto.php and run this as well this is in the dd-mysqli.php:

echo "<form method=post name=f1 action='chgoto.php'>";

to print the cat_id and subcategory, it is working, this is chgoto.php:

<?php
require 'config-mysqli.php';
//////// End of connecting to database ////////
$cat=$_POST['cat'];
$page=$_POST['subcat'];
echo "$cat <br> $page";
?>

the reslut is shown here:

1 (is cat_id)
3  (is subcategory

The problem is with the next php code, i want to add a sql query with two conditions in the chgoto.php to get the subcat2 value which is the url of html pages (as i run this mysql query in termianl in the begining of this post) but this is not working and there is only blank page in the output:

<?php
require 'config-mysqli.php';
//////// End of connecting to database ////////
$cat=$_POST['cat'];
$page=$_POST['subcat'];
$result = mysqli_query($connection,'SELECT subcat2 from subcategory  WHERE cat_id='.$cat.' AND subcategory='.$page.'');
$row = mysqli_fetch_assoc($result);
while($row = mysqli_fetch_assoc($result)){
        $url = $row['subcat2'];
        echo $url;
exit ;
}

$result->close();
$connection->close();
?>

I already enabled the php error log but no errors are reported for this query.

Link to comment
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.