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 06-19-2008, 05:57 PM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default using variables to run different queries

here is an excerpt of my code. i have navigation buttons and when each button and each button has a href of group.php?num=# where # is the group number i want to query. the problem is i did this and it wont work. for some reason the variable wont be passed. any ideas?

Code:
if(isset($num)) {
if($num = 1) {
	
	$viewrec = mysql_query("select * from tbl_clone where grp = '1' order by priority");
}

if($num = 2) {
	
	$viewrec = mysql_query("select * from tbl_clone where grp = '2' order by priority");
}

if($num = 3) {
	
	$viewrec = mysql_query("select * from tbl_clone where grp = '3' order by priority");
}

if($num = 4) {
	
	$viewrec = mysql_query("select * from tbl_clone where grp = '4' order by priority");
}

if($num = 5) {
	
	$viewrec = mysql_query("select * from tbl_clone where grp = '5' order by priority");
}

if($num = 6) {
	
	$viewrec = mysql_query("select * from tbl_clone where grp = '6' order by priority");
}

if($num = 7) {
	
	$viewrec = mysql_query("select * from tbl_clone where grp = '7' order by priority");
}

if($num = 8) {
	
	$viewrec = mysql_query("select * from tbl_clone where grp = '8' order by priority");
}

if($num = 9) {
	
	$viewrec = mysql_query("select * from tbl_clone where grp = '9' order by priority");
}


if($num = 10) {
	
	$viewrec = mysql_query("select * from tbl_clone where grp = '10' order by priority");
}

if($num = 0) {
	
	$viewrec = mysql_query("select * from tbl_clone where grp = 'notset' order by priority");
}
}
else { die('page not set'); }
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 06-19-2008, 06:29 PM   #2 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

nm, i found out i had to put == instead of =
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 06-19-2008, 07:38 PM   #3 (permalink)
The Contributor
 
Join Date: Mar 2008
Posts: 62
Thanks: 2
Seraskier is on a distinguished road
Default

heres a cleaner one.
Im writing it right here, so no testing.

Code:
//use some way to get the $i; ifs, using the date function, anyway you choose.
$i=rand(1,6)*2;

$mysql=mysql_query("select * from tbl_clone where grp = '.$i.' order by priority");
if(!mysql_query($mysql))
  { die('Could not process request.'); }
Send a message via MSN to Seraskier
Seraskier is offline  
Reply With Quote
Old 06-19-2008, 08:22 PM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

PHP Code:
if (isset($num)) {
    
$q sprintf("SELECT * FROM `tbl_clone` WHERE grp = '%d'"mysql_real_escape_string($num));
    if (!
mysql_query($q)) echo 'Invalid group ID';

-m
delayedinsanity is offline  
Reply With Quote
Old 06-19-2008, 08:29 PM   #5 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

just a tip, if you have a need for a conditional with that many different options depending on a single variable a switch is better suited:

PHP Code:
<?php
switch($num)
{
  case 
1:
    
$viewrec mysql_query("select * from tbl_clone where grp = '1' order by priority");
    break;
  case 
2:
    
$viewrec mysql_query("select * from tbl_clone where grp = '2' order by priority");
    break;
   ...

  default:
    die(
'Page not set');
}
PHP: switch - Manual
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 06-19-2008, 10:37 PM   #6 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

My version:

PHP Code:
<?php
    
if(!isset($num) || !is_numeric($num) || $num 0)
    {
        
$num 'notset';
    }
    else
    {
        
/** Force integer */
        
$num = (integer) $num;
    }

    
$query = @mysql_query('SELECT * FROM ... WHERE ... = $num');

    if(!
$query || !@mysql_num_rows($query))
    {
        
/** No page set or no results, halt execution */
    
}

    
/** Continue */
?>
Hope it helps ;)
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle 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 10:15 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