Jump to content

Generating a list from available products in database.


elmas156

Recommended Posts

Hello everyone,

 

I've been working on this for about 2 days now, and I just can't seem to figure it out so I need some help from someone here.  I have a database with three items (will be more, but for now there's three).  The database keeps a record of the days that each item is reserved.  I want to be able to select and generate a list of items that are available on a specific day.  Here is what I have so far:

 

<?php

$result = mysql_query("SELECT `prodid` FROM reservations WHERE `resdate` = '$resdate'") or die (mysql_error());

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

$resprodid = $row[0];

$result2 = mysql_query("SELECT `prodid`,`prodname` FROM products");
$row2 = mysql_fetch_row($result2);

$prodid = $row2[0];
$prodname= $row2[1];

if ($prodid != $resprodid) {

	echo $prodid;									

}

}

?>

 

The result that I'm getting are not correct. I either get only one unit listed, or none.  Any help would be appreciated.  Thanks!

Link to comment
Share on other sites

What does $resdate look like? is it a date, time, datetime?

 

I would also recommend doing a join.

<?php
$result = mysql_query("SELECT r.prodid, p.prodname FROM reservations as r left join products as p using(prodid) WHERE date(resdate) = date('$resdate')");
while ($row = mysql_fetch_assoc($result)) {
$prodid = $row["prodid"];
$prodname= $row["prodname"];
echo "$prodid<br />";
}
?>

Link to comment
Share on other sites

$resdate is actually a string that I created by using "explode" to adjust the format of the date() function.  The end result always look like "02/17/2012."  I've never used a "join," any way you could break it down and help me understand exactly what's going on in your code?  Thanks very much!

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.