TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-13-2009, 08:22 PM   #1 (permalink)
The Visitor
 
MattD's Avatar
 
Join Date: Feb 2009
Posts: 2
Thanks: 0
MattD is on a distinguished road
Default Wishing I had hair to pull out...

This is probably a very simple question but I have spent hours searching the web and cannot find an answer.

I am pulling records from a mysql database with SELECT * FROM sheet WHERE value = value(passed from a url)

This all works fine, but how on earth do I now get it to display all the records when I have WHERE cutting my options down.
I have tried passing 1+2+3 etc in the url but nothing seems to work.


I hope that makes sense.
MattD is offline  
Reply With Quote
Old 02-13-2009, 09:15 PM   #2 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Code:
SELECT * FROM sheet
...perhaps?
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 02-13-2009, 09:22 PM   #3 (permalink)
The Contributor
 
Join Date: Feb 2009
Posts: 65
Thanks: 0
Krik is on a distinguished road
Default

Showing us snippet of your code helps us show you how to specifically do it with your code.

But without that I can give you a few basic examples

In the following examples $rn could be the variable that you are passing from the url.

PHP Code:
$qry "
    SELECT *
    FROM Table
    WHERE `record_number` = 
$rn
"
;
$qry_res mysql_query($qry);

    while (
$qry_row mysql_fetch_array($qry_res)) {
    echo 
$qry_row[0$qry_row[1]; //ect
    

PHP Code:
$qry "
    SELECT *
    FROM Table
    WHERE `record_number` = 
$rn
"
;
$qry_res mysql_query($qry);

    while (
$qry_row mysql_fetch_array($qry_res)) {
    list( 
$rn$Col_1$Col_2 ) = $qry_row;
    echo 
$rn $Col_1 $Col_2;
    } 
PHP Code:
$qry "
    SELECT *
    FROM Table
    WHERE `record_number` = 
$rn
"
;
$qry_res mysql_query($qry);

$qry_rows mysql_num_rows($qry_res);

$qry_row mysql_fetch_array($qry_res)
    for(
$i 0$i $qry_rows$i++){
        foreach(
$qry_row[$i] => $key as $value) {
        echo 
$key $value;
        }
    } 
Now that is the nice readable neat simple examples
PHP Code:
$qry_row mysql_fetch_array(mysql_query(SELECT FROM Table WHERE `record_number` = $rn)); 
In the above example $qry_row is the same as all the previous $qry_row and you can append the for or while loops from the previous examples.

There is also a way to do it with a class but that is likely beyond you at this time. So hope that helps.

As a side note do to that high risk of SQL injections with passing variables from a URL I recommend you use mysql_real_escape_string() and htmlentities() as well as other security precautions.

Last edited by Krik : 02-13-2009 at 09:56 PM. Reason: posted an errant for loop
Krik is offline  
Reply With Quote
Old 02-13-2009, 11:13 PM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Do you still want to limit the result set? Assuming Xenon didn't answer your question, how about the following to limit the result set to just 1, 2 and 3:

sql Code:
SELECT * FROM myTable WHERE myColumn IN(1,2,3)
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 02-14-2009, 12:24 AM   #5 (permalink)
The Visitor
 
MattD's Avatar
 
Join Date: Feb 2009
Posts: 2
Thanks: 0
MattD is on a distinguished road
Default

Yes I want to be able to limit the results as well.
I have a jump menu which is carrying the value over, the 1,2,3 etc and lets me show an individual record just fine, the problem is with how to pass something from that menu to show all the records.
The code that is doing the selecting (I think, in the beginner section for a reason )
is

PHP Code:
$query_RSitems sprintf("SELECT * FROM items_list WHERE item_type = %s  AND items_list.item2_type = %s "GetSQLValueString($colname_RSitems"int"),GetSQLValueString($colname2_RSitems"int")); 
I am using echo from the recordset to show the info in the body.

Hope that explains better
MattD is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:29 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design