Jump to content

Please can somebody help?


Richlilley

Recommended Posts

Hello I have asked this before but not really sorted it out. I have set up the datadbase. The searcg function workd fine it finds the products from the Title, but the category list just returns the comment No Products Found.

 

Here is the code

 

On my mysql database i have Category_id in row 4, please help new to php!! Thanks

 

<?php

 

 

// open connection

$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

 

// select database

mysql_select_db($db) or die ("Unable to select database!");

 

 

// create query

if (! isset($search)) {

$query = "SELECT * FROM Products WHERE Category_id = 4";

} else {

$query = "SELECT * FROM  Products WHERE Title LIKE  '%$search%'";

 

}

 

// execute query

$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

 

// see if any rows were returned

if (mysql_num_rows($result) > 0) {

    // yes

    // print them one after another

ECHO "<table width='90%' height='257' border='0'>";

 

 

    while($row = mysql_fetch_array($result)) {

 

  ECHO "<tr>";

    ECHO "<td height='36' colspan='4'><span class='titlestyle'>$row[Title]</span></td>";

    ECHO "<tr>";

    ECHO "<td colspan='2' rowspan='2'><a href=";

echo "javascript:popupWindow('";

echo "productimages/index_PREVIEW_standmenu_0001.jpg',500,400);";

echo "><img src='productimages/$row[5]' width='150' height='150'></a></td>";

  ECHO "<td width='68%' height='127' colspan='2'><span class='descriptionstyle'>$row[Description]</span></td>";

    ECHO "</tr>";

 

  ECHO "<tr>";

    ECHO "<td>$row[Price]</td>";

    ECHO "<td><a href='add-to-basket.php?productID=$row[0]&cat=$cat'><img src='images/add-icon.gif' width='95' height='19'></a></td>";

  ECHO "</tr>";

  ECHO "<tr>";

    ECHO "<td colspan='4'><hr></td>";

   

  ECHO "</tr>";

 

  }

 

ECHO "</table>";

}

else {

    // no

    // print status message

    echo "<p align='center'><font color='#808080' face='Arial'>No products found.</font></p>";

}

 

// free result set memory

mysql_free_result($result);

 

// close connection

mysql_close($connection);

 

 

 

?>

 

Link to comment
Share on other sites

Hello have tried to change to

 

try doin it this way

$num=mysql_num_rows($result)

 

if($num!=0)

{

}

else{

}

 

still the same message unless I am putting in wrong place. Please shed some light:-

 

  <?php

 

 

// open connection

$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

 

// select database

mysql_select_db($db) or die ("Unable to select database!");

 

 

// create query

if (! isset($search)) {

$query = "SELECT * FROM Products WHERE Category_id = '4'";

} else {

$query = "SELECT * FROM  Products WHERE Title LIKE  '%$search%'";

 

}

 

// execute query

$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

 

// see if any rows were returned

if ($num=mysql_num_rows($result) > 0) {

   

// yes

    // print them one after another

ECHO "<table width='90%' height='257' border='0'>";

 

 

    while($row = mysql_fetch_array($result)) {

Link to comment
Share on other sites

not this way

// see if any rows were returned
if ($num=mysql_num_rows($result) > 0)

 

change it to

 

$num=mysql_num_rows($result);

if($num!=0)

{

}

 

SELECT * FROM Products WHERE Category_id = '4'"

copy this and paset it in the database n see if u get the record

 

if not try it without the quotes

Link to comment
Share on other sites

Hello thanks for your help.

 

Ive got a Products table and a Category table. Category_id is 4th row in the products table. Both tables are linked so a new category is placed in Category table in row 1 as CAT.

 

So what I am trying to get is when a new category is entered and stored, the link on the home page will find all products in that category??

 

Not sure if this helps

 

Rich

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.