[SOLVED] Query - Can't get desired results

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post 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.)
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I meant echoing $query, not $r.. as I said, $r is the result of the query.
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post 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
Last edited by cdickson on Tue Oct 05, 2004 1:51 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$selectdate is in the wrong format.
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post 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>
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post 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!
Post Reply