TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Wishing I had hair to pull out... (http://www.talkphp.com/absolute-beginners/3975-wishing-i-had-hair-pull-out.html)

MattD 02-13-2009 08:22 PM

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.

xenon 02-13-2009 09:15 PM

Code:

SELECT * FROM sheet
...perhaps?

Krik 02-13-2009 09:22 PM

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.

Wildhoney 02-13-2009 11:13 PM

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)

MattD 02-14-2009 12:24 AM

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


All times are GMT. The time now is 12:31 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0