Page 2 of 2

Posted: Tue Oct 05, 2004 12:43 pm
by cdickson
Well I certainly appreciate your help. I will keep working on this. There's another query on that page that I can modify and see what kind of results it produces.

Posted: Tue Oct 05, 2004 12:53 pm
by feyd
your original post had $r as the result of the query. It also runs the query twice, what does the code look like now? Could you post the echoing of the original post's query you are using?

Posted: Tue Oct 05, 2004 1:10 pm
by cdickson
If I do

Code: Select all

echo $r;
results = Resource id #4

I also tried commenting out the two lines just under the query:

Code: Select all

$r = mysql_query ($query);
$row = mysql_fetch_assoc($r);
and still get no results at all.

(Now I feel like I'm just trying dumb stuff - grasping at straws.)

Posted: Tue Oct 05, 2004 1:24 pm
by malcolmboston
resource ID #x is a common problem...
heres an example for you

Code: Select all

$query = "SELECT * FROM somewhere";
$result = mysql_query($query) or die (mysql_error())
$num_rows = mysql_num_rows($result)
// now conditionally get the resultset
if ($num_rows >= 1)
{
     // theres a resultset
     while ($array = mysql_fetch_array($result))
     {
          print {$array['something']};
     }
}
else
{
     // theres no results
     print "No Matches Found";
}
you can also use

Code: Select all

print "<pre>";
print_r($array);
print "</pre>";
after the resultset has been established to view all elements in the array

Posted: Tue Oct 05, 2004 1:41 pm
by feyd
I meant echoing $query, not $r.. as I said, $r is the result of the query.

Posted: Tue Oct 05, 2004 1:48 pm
by cdickson
Oops.

Result of echoing feyd's query is:
SELECT * FROM Login_users a INNER JOIN orders b ON b.userid = a.userid WHERE b.date = '10-05-2004' ORDER BY b.order_no
Result of echoing cdickson's query is:
SELECT * FROM orders, Login_users WHERE orders.date = '10-05-2004' ORDER BY orders.order_no ASC

Posted: Tue Oct 05, 2004 1:51 pm
by feyd
$selectdate is in the wrong format.

Posted: Tue Oct 05, 2004 1:53 pm
by cdickson
It echoes this way because I reformatted the date for printing purposes using the following code:

Code: Select all

$date = $row['date'];
$date_arr = explode('-', trim($date));
$order_date = ($date_arr[1].'-'.$date_arr[2].'-'.$date_arr[0]);
In the database it is still stored as YYYY-MM-DD.

Posted: Tue Oct 05, 2004 1:55 pm
by feyd
right.. but you are searching for the date to be the altered string.. not the original format. It'd more than likely not matching.

Posted: Tue Oct 05, 2004 2:29 pm
by cdickson
Even if $selectdate has the same date format?

Code: Select all

<select name="selectdate">
<?php
do {  
?>
<?php
 //Convert order date format
$date = $row3['date'];
$date_arr = explode('-', trim($date));
$order_date = ($date_arr[1].'-'.$date_arr[2].'-'.$date_arr[0]);
?>

<option value="<?php echo $order_date; ?>"><?php echo $order_date; ?></option>
<?php
} while ($row3 = mysql_fetch_assoc($result3));
$rows = mysql_num_rows($result3);
if($rows > 0) {
mysql_data_seek($result3, 0);
$row3 = mysql_fetch_assoc($result3);
}
?>
</select>

Posted: Tue Oct 05, 2004 2:39 pm
by cdickson
$feyd = Twisted BUT brilliant

:D

Thanks for the help. It was the code where I was trying to re-order the date. Since this is in an administrative area of the site, it may not matter.

THANKS!