PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 26th, 2012, 05:13 PM
nbasso713 nbasso713 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 64 nbasso713 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 36 m 11 sec
Reputation Power: 1
Problem Querying Multiple Rows

All I'm trying to do is create an array with all the id's that have a value of 0 in the status column of the table.

PHP Code:
 $query mysql_query("SELECT `tempID` FROM `pending` WHERE `status` = 0");
$status mysql_fetch_array($query); 


This codes has only been returning a single row any ideas?

Reply With Quote
  #2  
Old December 26th, 2012, 05:21 PM
AndrewSW's Avatar
AndrewSW AndrewSW is offline
JavaScript is not spelt java
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2011
Location: Landan, England
Posts: 743 AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 23 h 8 m 28 sec
Reputation Power: 164
The docs have the answer:
Quote:
mysql_fetch_array — Fetch a result row as an associative array, a numeric array, or both

To retrieve all values in the column you have to loop through them. Example (again from the docs):
PHP Code:
<?php
mysql_connect
("localhost""mysql_user""mysql_password") or
    die(
"Could not connect: " mysql_error());
mysql_select_db("mydb");

$result mysql_query("SELECT id, name FROM mytable");

while (
$row mysql_fetch_array($resultMYSQL_NUM)) {
    
printf("ID: %s  Name: %s"$row[0], $row[1]);  
}

mysql_free_result($result);
?>

You will need to modify this (or similar examples) to store the column values in a PHP array.

NB The mysql extension is deprecated and "will be removed in the future".

Reply With Quote
  #3  
Old December 26th, 2012, 06:03 PM
nbasso713 nbasso713 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 64 nbasso713 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 36 m 11 sec
Reputation Power: 1
Quote:
Originally Posted by AndrewSW
The docs have the answer:

To retrieve all values in the column you have to loop through them. Example (again from the docs):

You will need to modify this (or similar examples) to store the column values in a PHP array.


Awesome, thanks for the help works perfectly.

PHP Code:
while ($row mysql_fetch_array($queryMYSQL_NUM)) {
     
$status[$i] =  $row[0];
     
$i++;


Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Problem Querying Multiple Rows

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap