Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
This is a basic question, and I have some experience with PHP and databases. However, I can't seem to do this:
I just want to extract the contents of a row into an array. I've looked everywhere, but I only get sample codes that don't work.
Here is the portion of my code that is just returning a bunch of "Array" words in a row, instead of the strings that make up the row.
$result3 = mysql_query("SELECT * FROM VTABLE;") or die(mysql_error()); for($i = 0; $array[$i] = mysql_fetch_assoc($result3); $i++) ; //array_pop($array); echo $array[0] .' '. $array[1] .' '. $array[2] .' '. $array[3] .' '. $array[4] .' ';Any help would be appreciated.

I think I've found a temporary solution. I think I was looking in the wrong place: (the problem was that I was looking at the Ref ID, and not the table element names. (Also, in the example below, I was able to extract several values, by delimiting the SELECT names with a comma. An this is extracted with array syntax with the variable $row)
$result4 = mysql_query("SELECT num,PROGRESS FROM VTABLE WHERE num = '8'");$row = mysql_fetch_row($result4);
echo $row[0]; // 8, or the num value from above.
echo $row[1]; // the 'progress' value (from above)

I'm not sure if it's what you're after, but you can use print_r($array) to output the keys and values of an associative array.
In your first post,
$result3 = mysql_query("SELECT * FROM VTABLE;") or die(mysql_error()); if(mysql_num_rows($result3) > 0) { while($row = mysql_fetch_assoc($result3)) { print_r($row); echo "<br>"; } } or perhaps $result3 = mysql_query("SELECT * FROM VTABLE;") or die(mysql_error()); if(mysql_num_rows($result3) > 0) { while($row = mysql_fetch_assoc($result3)) { foreach($row as $key => $value) { echo $key . " = " . $value . "<br>"; } } }______________________
My work in progress. I hate JS. :P

Is there a way, once that databse is entered into a website to add the code needed for one of the columns in the mySql database ? I have a certain number of columns in my database and the first one is the "Add to Cart" column in which I want to stick a picture of a shopping cart with code links to the shopping cart form. I need to enter this code into each row of the Add to cart column and haven't found a way to do this yet.

Do you mean add / remove on an existing database / table? If so, then you'd need the alter privilege. You can either alter a database or a table.
If you mean update a column, then it would be something like
$res = mysql_query("update tbl_name set some_field=some_value where some_qualifier=some_requirement;");
If you need to insert a value, then
$res = mysql_query("insert into tbl_name values(...);");
HTH
______________________
My work in progress. I hate JS. :P

![]() |
Please tell me some WEBMA...
|
Prog to create HTML Menu
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |