Page 1 of 1
What's bad w/this code ?
Posted: Wed Nov 13, 2002 1:01 pm
by rax369
This code is not showing the firs element of my query:
Code: Select all
<?php
<select name="processors" id="processors">
<?
while ($row_processors = mysql_fetch_array($rs_processors))
{?>
<option>
<?
echo $row_processorsї'brand']; echo " - ";
echo $row_processorsї'name']; echo " - $"; echo $row_processorsї'price'];
?>
</option>
<? } ?>
<option selected><?php echo "Choose / Remove Product";?></option>
</select>
?>
The MySQL query is this one:
Code: Select all
SELECT brand, name, price
FROM products
WHERE category LIKE 'processors'
ORDER BY brand, name
And should show this elements, in this specific order: (forget the colum Record that appears there, I just took a snapshot from dreamweaver mx showing the result of my query to show u this

)
... so following how the code is ordering the info, the 1st. element in the drop down menu should be:
AMD - ATHLON 1.3 GHZ - $85.40
But what I'm getting is this ...
As you can see, the 1st. element (
AMD - ATHLON 1.3 GHZ - $85.40) is not appearing, why
thx for ur help
Posted: Wed Nov 13, 2002 1:03 pm
by volka
what's inbetween?
Code: Select all
<!-- somewhere must be a mysql_query -->
... what's here? ...
while ($row_processors = mysql_fetch_array($rs_processors))
Posted: Wed Nov 13, 2002 1:14 pm
by rax369
volka wrote:what's inbetween?
Code: Select all
<!-- somewhere must be a mysql_query -->
... what's here? ...
while ($row_processors = mysql_fetch_array($rs_processors))
ok, volka, here is the rest of the code:
Code: Select all
<?php
$query_rs_processors = "SELECT brand, name, price FROM products WHERE categoria LIKE 'processors' ORDER BY brand, name";
$rs_processors = mysql_query($query_rs_processors, $ST_Prods_Connection) or die(mysql_error());
?>
What do u think I'm not doing correct

Posted: Wed Nov 13, 2002 1:22 pm
by volka
then I'm clueless or blind - probably both

Posted: Wed Nov 13, 2002 2:58 pm
by rax369
I dont know what to do, I have ever done this in that way, and know, PHP comes w/that problem
HELP PLEASE

your code
Posted: Wed Nov 13, 2002 3:27 pm
by phpScott
I took your code and modified it to do almost what I do in simillar situations.
Hope fully this will work for you. I am hoping the syntax comes out alright as I don't have the same db set up to test it. This is just plain substitution so it should work, maybe, hopefully, finger crossed
Code: Select all
<?php
<select name="processors" id="processors">
<option selected>Choose / Remove Product</option>
<?php
while ($row_processors = mysql_fetch_array($rs_processors))
{
print"<option>".$row_processorsї'brand']." - ".$row_processorsї'name']." - $". $row_processorsї'price']."</option>";
}
?>
</select>
?>
phpScott
Posted: Wed Nov 13, 2002 3:30 pm
by volka
when I reach the state "damn, it must work. I know it works. somebody is playing tricks on me" I try to isolate the problem, creating a new program that does nothing else but this code fragment. In your case maybe something like
Code: Select all
<html><body><?php
include 'database_connection.php';
$query_rs_processors = "SELECT brand, name, price FROM products WHERE categoria LIKE 'processors' ORDER BY brand, name";
$rs_processors = mysql_query($query_rs_processors, $ST_Prods_Connection) or die(mysql_error());
echo '#records :', mysql_num_rows($ST_Prods_Connection);
echo '<table border="1"><tr>';
for ($i=0; $i!=mysql_num_fields($rs_processors); $i++)
echo '<th>', mysql_field_name($rs_processors, $i);
while ($row_processors = mysql_fetch_row($rs_processors))
{
echo '<tr>';
foreach($row_processors as $value)
echo '<td>', $value, '</td>';
echo '</tr>';
}
echo '</table>';
?></body></html>
(completely untested, not even by compiler

)
If this still does not process as expected I go on simplifying (skipping the ORDER BY then maybe the WHERE clause and so on).
But always keep in mind that you have to reintegrate your changes, so remeber what you did and keep the fragment small

Posted: Wed Nov 13, 2002 10:47 pm
by rax369
I did exactly what u told me phpScott, I even pasted ur code into my page, but what I got was the same result... the first element of the query is not appearing
this is so stupid, that is not working, I dont know what's bad.
I did as well what volka recommeded me, I and tried to exclude this especific problem, reencoding it at a new page, but cannt get it still.
aaargh

, I feel sometimes that PHP functions doesnt works the way they are suppoustly to work. The function I'm dealing with is pretty simple...
mysql_fetch_array... but it doesnt wanna work at all
If for some reason comes to ur mind guys, a possible solution to this stupid problem, please show it here.
I'm probably blind as well volka, I cannt locate the problem.
thx

Posted: Thu Nov 14, 2002 2:50 am
by twigletmac
When you used volka's code how many results did it say the query returned?
Mac
Posted: Thu Nov 14, 2002 8:07 am
by rax369
Forget what I said, I found the origin of my problem... DREAMWEAVER MX
this program sometimes I dont know why, but it generates lines of PHP code that u dont need, lines that u even havent typed, I what I have realized is that once u use the function 'mysql_fetch_array' over one variable storing some query, u cannt use it again right
may be u have u do another query to ur db, store it in some variable, and use again some function like this one (e.g. mysql_fetch_array, mysql_fetch_row, mysql_fetch_assoc, ... etc.)
let's give an example to leave my point clear:
Code: Select all
<?
$query_rs_processors = "SELECT brand, name, price FROM products WHERE categoria LIKE 'processors' ORDER BY brand, name";
$rs_processors = mysql_query($query_rs_processors, $ST_Prods_Connection) or die(mysql_error());
?>
<select name="processors" id="processors">
<option selected><?php echo "Choose / Remove Product";?></option>
<?
while($row_processors = mysql_fetch_array($rs_processors))
{
print"<option>".$row_processorsї'brand']." - ".$row_processorsї'name']." - $".$row_processorsї'price']."</option>";
}
?>
</select>
So because I already used the function 'mysql_fetch_array' to 'extract' the info from '$rs_processors' I cannt use again 'mysql_fetch_array' over that variable. Even if a copy the content of that variable to other before use this function (e.g $rs_processors2 = $rs_processors) even so I wouldnt able to use this function to extract the info, now from $rs_processors2, I dont know why.
could u explain me guys, this what I have found about these functions
thx again guys for all ur help
cheers !:D
Posted: Thu Nov 14, 2002 7:27 pm
by hob_goblin
try this:
Code: Select all
<?php
include 'database_connection.php';
$query_rs_processors = "SELECT brand, name, price FROM products WHERE categoria LIKE 'processors' ORDER BY brand, name";
$rs_processors = mysql_query($query_rs_processors, $ST_Prods_Connection) or die(mysql_error());
while($data = mysql_fetch_assoc($rs_processors)){
echo "<pre>";
print_r($data);
echo "</pre>";
}
?>
what does that return?