Question:
PHP & mysql - Select all cols from 1 row - not working?
n!ch0
2010-11-01 15:05:52 UTC
I'm going to re-word this because it seems people aren't understanding what I'm trying to say.

Visit: http://phpeasystep.com/mysql/6.html
One year ago, using the method on this website, I was able to select all columns from 1 row in a table and display those values anywhere I wanted to on a page.

------------------Quote From Website------------------

// Select all columns from one row.
"SELECT * FROM table_name WHERE column_name=' value in column '";
...
If you don't want looping rows in mysql, replace
while($rows=mysql_fetch_array($result)){
........
with this
$rows=mysql_fetch_array($result);

------------------Quote From Website------------------

People have been telling me the problem is that the syntax is wrong, that the values in the database are wrong, that my brother's dog is eating his food wrong and someone tripped on a wire...
NO. I appreciate all the help from the same problem in a previous question, but I've tried all your suggestions prior to you all suggesting them, and they still didn't work (before and after)

I know this because I'm able to print ALL values from a table using a while loop

However, when I attempt to grab all the columns from one row using:
$sql = "SELECT * FROM users WHERE id='$id'";
$result = mysql_query($sql);
$rows = mysql_fetch_array($rows);

It doesn't work. I can honestly say, I used this EXACT method one year ago - flawlessly. No problems. If I told it to jump, it would. So, what gives? Any help would be appreciated
Three answers:
Macadameane
2010-11-01 15:11:16 UTC
You do know that the line below is wrong.

$rows = mysql_fetch_array($rows);



It may just be a typo, but I think you mean $result in the parens instead of $rows.



EDIT:

Okay, interesting problem. But it seems sound. Can you post more code, or perhaps just sent me the code via a message? You said it works in the loop. Can you also explain what you mean by it doesn't work? Is there nothing at all in the array when you are done? Have you tried a print_r() on the array?
John S
2010-11-05 04:24:42 UTC
If your query returns only 1 row you can still use the while loop it will just stop after the first row. To be sure you only get one row append "and rownum < 2" to your where clause.
ChrisS
2010-11-02 00:04:51 UTC
Would need to see more code, or ya over msn or something to see whats what.



also try:



$result = mysql_query($sql) or die(mysql_error());



that will tell you if mysql is crapping out for some weird reason.



msn: chrisschneck@hotmail.com


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...