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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.