Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-17-2012, 06:30 PM   PM User | #1
sonny
Regular Coder

 
sonny's Avatar
 
Join Date: Apr 2008
Location: United States
Posts: 567
Thanks: 88
Thanked 0 Times in 0 Posts
sonny can only hope to improve
do query based on a var

Hi, is this the best way to switch a query

PHP Code:
$index $_GET['index'];
if (
$index==1$index=1;

if (
$index==1$query1 "SELECT COUNT(*) as num FROM $tbl WHERE test='1'";
else 
$query1 "SELECT COUNT(*) as num FROM $tbl WHERE ip LIKE '$key'"
Thanks
Sonny

Last edited by sonny; 10-17-2012 at 06:58 PM..
sonny is offline   Reply With Quote
Old 10-17-2012, 06:56 PM   PM User | #2
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
Quote:
Originally Posted by sonny View Post
Hi, I am trying to do a query based on $index==1, but its always running the else
I know the get works coming in, because I can echo $title, or maybe you can't do
that with a query or something.

PHP Code:
$index $_GET['index'];
if (
$index==1) {
$index=1;
$title="Index";// this works, but not the right query below?
}

if (
$index==1$query1 "SELECT COUNT(*) as num FROM $tbl WHERE test='1'";
else 
$query1 "SELECT COUNT(*) as num FROM $tbl WHERE ip LIKE '$key'"
Doesn't make much sense why it doesn't, but try converting the $_GET['index'] to an integer(intval) just for debugging purpose. Maybe the string interger comparison is conflicting although PHP automatically converts them for you during comparison.

PHP Code:

$index 
intval($_GET['index']); 
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk
Redcoder is offline   Reply With Quote
Old 10-17-2012, 07:08 PM   PM User | #3
sonny
Regular Coder

 
sonny's Avatar
 
Join Date: Apr 2008
Location: United States
Posts: 567
Thanks: 88
Thanked 0 Times in 0 Posts
sonny can only hope to improve
Know what, I had no "ones" in the test column my host must have restored the database or
something while I was working. just trying to slime things down , like turning 3 pages into one,
whenever I can.

I thought I was losing it, I never had a database change on me like that. sometimes I can
be too quick to blame myself, note for the record I clean everything just never post that part
to keep things simple as well as use isset etc

Sonny
sonny is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 01:49 AM.


Advertisement
Log in to turn off these ads.