Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
query to display multiple rows
Old 12-29-2011, 04:25 PM query to display multiple rows
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
Hello, im having trouble with this code, i have a page where u can reserve driver to do some tasks, i need to implement a new feature that lets the user see what task is the driver scheduled for.

i want to get the type of the task and display it so that the user can see what he is doing at that time right now im trying with this. this driver has 3 reservations for the same day, each with three different task. task1 = dc_run task2 = removal task3 = dressing so when i eco this it only shows dc_run which is from 8am to 11 am. how can i display it the 3 different tasks hes scheduled for? i would the output to be like this
8am - 11am : dc_run. 12pm - 3pm : removal 4pm - 6pm : dressing.
here it only shows the first record and not the other two..

thanks for your help
PHP Code:
$sqltype ="SELECT res_startTime,res_endTime,type FROM reservation WHERE res_date='$actDate' AND res_driver_id=1 ORDER BY res_startTime";
  
$rstype1 mysql_fetch_array(mysql_query($sqltype));
  
 echo 
$rstype1['res_startTime'] . " - " $rstype1['res_endTime'] . " : " $rstype1['type']; 
stivens is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-29-2011, 04:32 PM Re: query to display multiple rows
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://www.tizag.com/mysqlTutorial/mysqlfetcharray.php
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-29-2011, 04:33 PM Re: query to display multiple rows
miki86's Avatar
Extreme Talker

Posts: 185
Location: print_r($serbia);
Trades: 0
PHP Code:
$sqltype ="SELECT res_startTime,res_endTime,type FROM reservation WHERE res_date='$actDate' AND res_driver_id=1 ORDER BY res_startTime"
$result mysql_query($sqltype);
     
    while(
$rstype1 mysql_fetch_assoc($result)) {
        echo 
$rstype1['res_startTime'] . " - " $rstype1['res_endTime'] . " : " $rstype1['type'];
    } 
miki86 is online now
Reply With Quote
View Public Profile
 
Old 12-29-2011, 04:36 PM Re: query to display multiple rows
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
Quote:
Originally Posted by miki86 View Post
PHP Code:
$sqltype ="SELECT res_startTime,res_endTime,type FROM reservation WHERE res_date='$actDate' AND res_driver_id=1 ORDER BY res_startTime"
$result mysql_query($sqltype);
     
    while(
$rstype1 mysql_fetch_assoc($result)) {
        echo 
$rstype1['res_startTime'] . " - " $rstype1['res_endTime'] . " : " $rstype1['type'];
    } 
THANK YOU SO MUCH!! this works perfect!!!
stivens is offline
Reply With Quote
View Public Profile
 
Old 12-29-2011, 05:23 PM Re: query to display multiple rows
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
i tried showing the results as a link so i did this

PHP Code:
while($rstype1 mysql_fetch_assoc($result)) { 
            echo 
'<a href="edit_misa.php?resid='.$rstype1['res_id'].'" >'.format_time($rstype1['res_startTime']) . ' - ' format_time($rstype1['res_endTime']) . ' : ' $rstype1['type'] . '</a> '
            } 
but it doesnt show as a link for the first record only for the last two..

i dont get why this is happening? if it is a loop isnt it supposed to be the same for all of them?
stivens is offline
Reply With Quote
View Public Profile
 
Old 12-30-2011, 03:59 AM Re: query to display multiple rows
miki86's Avatar
Extreme Talker

Posts: 185
Location: print_r($serbia);
Trades: 0
Quote:
Originally Posted by stivens View Post
i dont get why this is happening? if it is a loop isnt it supposed to be the same for all of them?
Yes.
I don't know what type of data you have stored in your db, but maybe you should try to url encode it:

PHP Code:
while($rstype1 mysql_fetch_assoc($result)) {  
     echo 
'<a href="edit_misa.php?resid='.urlencode($rstype1['res_id']).'" >'.format_time($rstype1['res_startTime']) . ' - ' format_time($rstype1['res_endTime']) . ' : ' $rstype1['type'] . '</a> ';  

miki86 is online now
Reply With Quote
View Public Profile
 
Old 12-30-2011, 01:27 PM Re: query to display multiple rows
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
Thanks miki86,

the urlencode didn't work. the type of field is an int(11) auto-increment.. i just dont get why it works for the last two but it doesn't work for the first one..
stivens is offline
Reply With Quote
View Public Profile
 
Old 12-30-2011, 10:06 PM Re: query to display multiple rows
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Try adding a var_dump() to see what is actually returned from the database.
PHP Code:
while ($rstype1 mysql_fetch_assoc($result)) {
    echo 
'<pre>';
    
var_dump($rstype1);
    echo 
'</pre>';

    echo 
'<a href="edit_misa.php?resid='.urlencode($rstype1['res_id']).'" >'.format_time($rstype1['res_startTime']) . ' - ' format_time($rstype1['res_endTime']) . ' : ' $rstype1['type'] . '</a> ';   

__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to query to display multiple rows
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27381 seconds with 12 queries