473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help in displaying all the record instead of 1

93
Hi ppl I need help with my php basically I manage to get my php to display the uname that matches the sql condition however it only return 1 record when there are 2 record that match the condition how do I make it display all record that matches the condition instead of displaying just one?
This is my code:
[PHP]
$resultpostal=mysql_query("SELECT location.uname,location.uid FROM location,districts WHERE districts.districtno ='56' AND
location.lat BETWEEN districts.startlat AND districts.endlat AND location.lng BETWEEN districts.startlng AND districts.endlng");

$counterx=0;
if($row=mysql_fetch_array($resultpostal)){
foreach($row as $col_value){
$temp[$counterx]=$col_value;
$counterx++;
}





$report.="uid"."=".$temp[0]."&";
$report.="uname"."=".$temp[1]."&";




echo $report;


[/PHP]
Aug 4 '07 #1
19 1689
pbmods
5,821 Expert 4TB
Heya, Rocky.

Change this line:
Expand|Select|Wrap|Line Numbers
  1. if($row=mysql_fetch_array($resultpostal)){
  2.  
to:
Expand|Select|Wrap|Line Numbers
  1. while($row=mysql_fetch_assoc($resultpostal)){
  2.  
s/if/while/
s/array/assoc/
Aug 4 '07 #2
Rocky86
93
Heya, Rocky.

Change this line:
Expand|Select|Wrap|Line Numbers
  1. if($row=mysql_fetch_array($resultpostal)){
  2.  
to:
Expand|Select|Wrap|Line Numbers
  1. while($row=mysql_fetch_assoc($resultpostal)){
  2.  
s/if/while/
s/array/assoc/

Hey pbmods I did what you mention but it does not seen to work at all it just basically return me the value "3"

while($row=mysql_fetch_array($resultpostal)){

After I change back then it still return me one record but when I do a testing on the SQL statement it return me 2 record but in php it just return me 1
Aug 4 '07 #3
pbmods
5,821 Expert 4TB
Heya, Rocky.

Let's organize your code real quick:

Expand|Select|Wrap|Line Numbers
  1. $temp = array();
  2.  
  3. while($row = mysql_fetch_assoc($resultpostal))
  4. {
  5.     $temp[] = $row;
  6. }
  7.  
  8. print_r($temp);
  9.  
Put this right after your MySQL query and get rid of everything else below it.
Aug 4 '07 #4
Rocky86
93
Heya, Rocky.

Let's organize your code real quick:

Expand|Select|Wrap|Line Numbers
  1. $temp = array();
  2.  
  3. while($row = mysql_fetch_assoc($resultpostal))
  4. {
  5.     $temp[] = $row;
  6. }
  7.  
  8. print_r($temp);
  9.  
Put this right after your MySQL query and get rid of everything else below it.
I did as you suggest it now return me nothing at all worse then just now this statement iszit to check if it return all the recordS?
Aug 5 '07 #5
jx2
228 100+
I did as you suggest it now return me nothing at all worse then just now this statement iszit to check if it return all the recordS?
pbmods is right!!

insted of giving u the answer i try to explain you how it works

it dosnt return just one record!!(if there are records matching your criteria) it return THE FIRST RECORD ONLY!!!
if u want the second record u need to call mysql_fetch_array() or mysql fech row() again and again

therefore pbmods sugested you to change "if" to "while"

there is ofcurse posible your query doesnt math anything

i sugest to try somthing simplier at the begining and modify it to your needs later

[PHP]
$result = mysql_query(" SELECT * FROM yourtable");
echo "<table>";
while($record = mysql_fetch_row($result))
{
//notice i do not compare it i asign it (single "=" not "==")
// the statment above is true as long as thre are records to read
// $record is an array!! therefore:
echo "<tr>";
foreach($record as $var){
echo "<td>$var</td>";
}
echo "</tr>";
}
echo "</table>";
[/PHP]

that should display all records in your table
you can modify the query to your need later

i hope that helps
jx2
Aug 5 '07 #6
pbmods
5,821 Expert 4TB
Heya, Rocky.

I did as you suggest it now return me nothing at all worse then just now this statement iszit to check if it return all the recordS?
I put up that code to help you understand what the code is doing.

The solution to your problem is actually quite simple, but only if you know how your code works.
Aug 5 '07 #7
Rocky86
93
Heya, Rocky.



I put up that code to help you understand what the code is doing.

The solution to your problem is actually quite simple, but only if you know how your code works.
Hey pbmods that code you put is just returning the record that match my sql statement that all what is the solution to my problem plss help
Aug 5 '07 #8
Rocky86
93
pbmods is right!!

insted of giving u the answer i try to explain you how it works

it dosnt return just one record!!(if there are records matching your criteria) it return THE FIRST RECORD ONLY!!!
if u want the second record u need to call mysql_fetch_array() or mysql fech row() again and again

therefore pbmods sugested you to change "if" to "while"

there is ofcurse posible your query doesnt math anything

i sugest to try somthing simplier at the begining and modify it to your needs later

[PHP]
$result = mysql_query(" SELECT * FROM yourtable");
echo "<table>";
while($record = mysql_fetch_row($result))
{
//notice i do not compare it i asign it (single "=" not "==")
// the statment above is true as long as thre are records to read
// $record is an array!! therefore:
echo "<tr>";
foreach($record as $var){
echo "<td>$var</td>";
}
echo "</tr>";
}
echo "</table>";
[/PHP]

that should display all records in your table
you can modify the query to your need later

i hope that helps
jx2
hey jx2 basically the code you post is returning all the record which not what I want to acheive for my case I need to compare the value and return the uname and uid of whoever that matches my sql condition right now my code is able to just return 1 record instead of all the record that matches the condition trying to make it display not just 1 but all the record that matches the sql condition
Aug 5 '07 #9
kovik
1,044 Expert 1GB
hey jx2 basically the code you post is returning all the record which not what I want to acheive for my case I need to compare the value and return the uname and uid of whoever that matches my sql condition right now my code is able to just return 1 record instead of all the record that matches the condition trying to make it display not just 1 but all the record that matches the sql condition
He's not writing the code for you, he's giving you an example of how to retrieve data from a query result. If you want it to match your SQL, then replace the query he gave to you with your query.

I really suggest that you go back and read some beginner's tutorials. You seem to keep thinking that everyone is writing your code for you when all we're doing is trying to teach you, and if you understood the code instead of just copying and pasting it, you'd know that. There's are plenty of books available as well to help you 'break out' of being a novice programmer into an intermediate stage.
Aug 5 '07 #10
Rocky86
93
He's not writing the code for you, he's giving you an example of how to retrieve data from a query result. If you want it to match your SQL, then replace the query he gave to you with your query.

I really suggest that you go back and read some beginner's tutorials. You seem to keep thinking that everyone is writing your code for you when all we're doing is trying to teach you, and if you understood the code instead of just copying and pasting it, you'd know that. There's are plenty of books available as well to help you 'break out' of being a novice programmer into an intermediate stage.
I understand the mysql_fetch_array is only able to fetch the first row but not the second or third and so on But I reallx want to know how to do that? able to fetch not just the first row but all the row that match the sql condition pls help
Aug 6 '07 #11
dafodil
392 256MB
Hey man. You should really study. I checked all your posts. It seems you're not really interested in learning. I adviced you already in your previous thread. Are you using this site to create your own project? Its not good.

This site is a good start for learning: http://w3schools.com/

you can also try this: http://movielibrary.lynda.com/html/modPage.asp?ID=435

Your previous thread already came up to 28 posts with simple questions that's not hard to understand...

With a thread title how to use logic for my code?. That's shows how lazy you are, you even want us to solve the logic of your program.

When all you need to learn is the syntax of the language and the logic is the application of it!!!!!
Aug 6 '07 #12
Rocky86
93
how come the uid is undefined value on the actionscripts? the uname is able to be display but the uid is undefinded I don't see any wrong with my code but I don't know why it return undefinded value?
[PHP]
$counterx=0;
if($row=mysql_fetch_array($resultpostal)){
foreach($row as $col_value){
$temp[$counterx]=$col_value;
$counterx++;
}





$report.="uid"."=".$temp[0]."&";
$report.="uname"."=".$temp[1]."&";




echo $report;


[/PHP]
Aug 6 '07 #13
kovik
1,044 Expert 1GB
You need to start doing some debugging. Make your ActionScript display everything from the PHP file, and start making the PHP file echo out everything that you can. There is no magic solution... You HAVE to put forth some effort.
Aug 6 '07 #14
Rocky86
93
You need to start doing some debugging. Make your ActionScript display everything from the PHP file, and start making the PHP file echo out everything that you can. There is no magic solution... You HAVE to put forth some effort.
I understand I will do it thx
Aug 6 '07 #15
Rocky86
93
You need to start doing some debugging. Make your ActionScript display everything from the PHP file, and start making the PHP file echo out everything that you can. There is no magic solution... You HAVE to put forth some effort.
Hey volectricity I did alot of testing and I realize that it keep returning me the same value for both the uname and uid:

uid=Khali Signh&uname=Khali Signh&

this is what I get what is wrong with it I don't know why the uid is displaying the same value as the uname when it should be displaying uid
Aug 6 '07 #16
pbmods
5,821 Expert 4TB
Heya, Rocky.

Quick, what's the difference between if and while?

The answer to that question is the reason why you're only getting one record.

If you don't know the answer to that question, you might want to consider picking up a PHP programming book, or else have a look at PHP Control Structures.
Aug 6 '07 #17
Rocky86
93
Heya, Rocky.

Quick, what's the difference between if and while?

The answer to that question is the reason why you're only getting one record.

If you don't know the answer to that question, you might want to consider picking up a PHP programming book, or else have a look at PHP Control Structures.
Hey pbmods I noe the different between the if and while if just loop through 1 record while loop through all the record until that is no matching result but I try both using if and while it still return me the same thing
Aug 6 '07 #18
pbmods
5,821 Expert 4TB
Heya, Rocky.

Never mind me. Upon closer inspection, your problem is actually here.

Expand|Select|Wrap|Line Numbers
  1. foreach($row as $col_value)
  2. {
  3.     $temp[$counterx] = $col_value;
  4.     $counterx++;
  5. }
  6.  
You'll want to change that entire block to simply:
Expand|Select|Wrap|Line Numbers
  1. $temp[] = $row;
  2.  
Then to create $report:
Expand|Select|Wrap|Line Numbers
  1. $report = '';
  2. foreach($temp as $row => $data)
  3. {
  4.     $report .= ($report ? '?' : '&') . "uid={$data[0]}&uname={$data[1]}";
  5. }
  6.  
Aug 6 '07 #19
Rocky86
93
Heya, Rocky.

Never mind me. Upon closer inspection, your problem is actually here.

Expand|Select|Wrap|Line Numbers
  1. foreach($row as $col_value)
  2. {
  3.     $temp[$counterx] = $col_value;
  4.     $counterx++;
  5. }
  6.  
You'll want to change that entire block to simply:
Expand|Select|Wrap|Line Numbers
  1. $temp[] = $row;
  2.  
Then to create $report:
Expand|Select|Wrap|Line Numbers
  1. $report = '';
  2. foreach($temp as $row => $data)
  3. {
  4.     $report .= ($report ? '?' : '&') . "uid={$data[0]}&uname={$data[1]}";
  5. }
  6.  

Hey pbmods I manage to get the both the uid and uname to be display actionscripts by this php code I did:

[PHP]
$report = "&";

$counterx=0;
while($row=mysql_fetch_assoc($resultpostal)){
foreach($row as $col_value){
$temp[$counterx]=$col_value;
$counterx++;
}


$report.="uid"."=".$temp[1]."&";
$report.="uname"."=".$temp[0]."&";



echo $report;

[/PHP]

Thx I finally manage to do it with a different method after trying and trying
Aug 7 '07 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: millw0rm | last post by:
Hi, here is the complete detail what i m trying 2 do. i got around 2000+ images with size/desp/image_no/slno etc TABLE `sheet1` ( `SlNo` int(11) NOT NULL auto_increment, `Image No` double...
6
by: Matt K. | last post by:
Hi there, I have a form in an Access project that contains a subform which displays the results of a query of the style "select * from where = #a certain date#". In the main part of the form...
13
by: Aladdin | last post by:
I have an MS Access form on which I have a listbox listing tables in that database. I want to be able to click on any of those tables and view its contents on the same form using subforms or any...
4
by: Tom Keane | last post by:
Okay, woo, yet another issue I have. I remember writing about this issue AGES ago, but I don't think it worked, or I just left it for too long. I have a query that searches for specific records...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
13
by: David W. Fenton | last post by:
I've been struggling the last two days with something I thought was very easy, which is to open a web page with a form on it and populate the form with data passed in a query string (either POST or...
9
by: TF | last post by:
Hello all, I made a ASP.NET 2.0 site that shows possible "recipes" for paint colors stored in an access dbase. Basically, 1000 colors are stored with specific RGB values in separate columns. A...
2
by: alana001 | last post by:
I'm sure this is incredibly simple, I just haven't been able to find the magic search string for Google. :) The basic question is: What VB function do I use to update the value of a text box each...
3
by: raaman rai | last post by:
Please help me with the following code. I have used this pagination script from the net and customized it but unfortunately it doesnt work as expected. The problem is, for the trial purpose i have 3...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.