[SOLVED] Query - Can't get desired results
Moderator: General Moderators
If I do
results = Resource id #4
I also tried commenting out the two lines just under the query:
and still get no results at all.
(Now I feel like I'm just trying dumb stuff - grasping at straws.)
Code: Select all
echo $r;I also tried commenting out the two lines just under the query:
Code: Select all
$r = mysql_query ($query);
$row = mysql_fetch_assoc($r);(Now I feel like I'm just trying dumb stuff - grasping at straws.)
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
resource ID #x is a common problem...
heres an example for you
you can also use
after the resultset has been established to view all elements in the array
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";
}Code: Select all
print "<pre>";
print_r($array);
print "</pre>";Oops.
Result of echoing feyd's query is:
Result of echoing feyd's query is:
Result of echoing cdickson'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
SELECT * FROM orders, Login_users WHERE orders.date = '10-05-2004' ORDER BY orders.order_no ASC
Last edited by cdickson on Tue Oct 05, 2004 1:51 pm, edited 1 time in total.
It echoes this way because I reformatted the date for printing purposes using the following code:
In the database it is still stored as YYYY-MM-DD.
Code: Select all
$date = $row['date'];
$date_arr = explode('-', trim($date));
$order_date = ($date_arr[1].'-'.$date_arr[2].'-'.$date_arr[0]);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>