Jump to content


Photo

WHERE column IN (value,value) problem


  • Please log in to reply
8 replies to this topic

#1 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 15 July 2006 - 02:45 AM

heres the code:

$pid = $_GET[pid];

if($pid == ''){
echo "No Platform ID Specified.";
include('includes/footer.php');
}ELSE{

if($pid == '12'){
$sqlthing = 'WHERE newsecid IN (12,34,35,36,37,38,40,41,42,43,45,46,48)';
}
if($pid == '13'){
$sqlthing = 'WHERE newsecid IN (13,35,36,37,39,40,41,42,43,44,45,46,47)';
}
if($pid == '14'){
$sqlthing = 'WHERE newsecid IN (14,34,35,36,37)';
}
if($pid == '20'){
$sqlthing = 'WHERE newsecid IN (20,38,39,40,41,44,45,47)';
}
if($pid == '32'){
$sqlthing = 'WHERE newsecid IN (32,41,42,44,45,47)';
}
if($pid == '16'){
$sqlthing = 'WHERE newsecid IN (16,48)';
}ELSE{
$sqlthing = 'WHERE newsecid = $pid';
}

if (!$link = mysql_connect($sqlserver, $sqlusername, $sqlpassword)) {
   echo 'Could not connect to mysql';
   exit;
}

if (!mysql_select_db($sqldatabase, $link)) {
   echo 'Could not select database';
   exit;
}

$query="SELECT * FROM nuke_seccont $sqlthing AND fletter = 'A'";
$result = mysql_query($query);

while ($row = mysql_fetch_array($result)) {

$title = stripslashes($row["title"]);
$artid = stripslashes($row["artid"]);
$counter = stripslashes($row["counter"]);

echo "<tr>
        <td><b><a href=\"review.php?artid=$artid\" title=\"$counter hits\">$title</a></b></td>
    </tr>";

$i++;
}
}
?>

(It does that last bit of code once for each letter)

No errors, but no results, from ANY of the values specified!
http://www.DaveLinger.com
dave at linger dot com

#2 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 15 July 2006 - 02:47 AM

shouldnt it have
mysql_query
then the WHERE section ?

#3 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 15 July 2006 - 02:50 AM

how are you building the query after that?  have you tried echoing the query you end up with in the end (before running it)?

#4 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 15 July 2006 - 02:53 AM

<?php
$pid = $_GET[pid];

if($pid == ''){
echo "No Platform ID Specified.";
include('includes/footer.php');
}ELSE{

if($pid == '12'){
$sqlthing = mysql_query('WHERE newsecid IN (12,34,35,36,37,38,40,41,42,43,45,46,48)') or die(mysql_error());
//shouldnt they all be like this
//shouldnt they all be like this
//shouldnt they all be like this

}
if($pid == '13'){
$sqlthing = 'WHERE newsecid IN (13,35,36,37,39,40,41,42,43,44,45,46,47)';
}
if($pid == '14'){
$sqlthing = 'WHERE newsecid IN (14,34,35,36,37)';
}
if($pid == '20'){
$sqlthing = 'WHERE newsecid IN (20,38,39,40,41,44,45,47)';
}
if($pid == '32'){
$sqlthing = 'WHERE newsecid IN (32,41,42,44,45,47)';
}
if($pid == '16'){
$sqlthing = 'WHERE newsecid IN (16,48)';
}ELSE{
$sqlthing = 'WHERE newsecid = $pid';
}

if (!$link = mysql_connect($sqlserver, $sqlusername, $sqlpassword)) {
   echo 'Could not connect to mysql';
   exit;
}

if (!mysql_select_db($sqldatabase, $link)) {
   echo 'Could not select database';
   exit;
}

$query="SELECT * FROM nuke_seccont $sqlthing AND fletter = 'A'";
$result = mysql_query($query);

while ($row = mysql_fetch_array($result)) {

$title = stripslashes($row["title"]);
$artid = stripslashes($row["artid"]);
$counter = stripslashes($row["counter"]);

echo "<tr>
        <td><b><a href=\"review.php?artid=$artid\" title=\"$counter hits\">$title</a></b></td>
    </tr>";

$i++;
}
}
?>


#5 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 15 July 2006 - 02:57 AM

gar, I echoed the query and it is:

"SELECT * FROM nuke_seccont WHERE newsecid = $pid AND fletter = '0-9'"

but the $_GET[pid] is '12'

X.X
http://www.DaveLinger.com
dave at linger dot com

#6 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 15 July 2006 - 03:00 AM

maybe there's something wrong with my if statement? pid=16 creates a correct query...

"SELECT * FROM nuke_seccont WHERE newsecid IN (16,48) AND fletter = '0-9'"
http://www.DaveLinger.com
dave at linger dot com

#7 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 15 July 2006 - 03:03 AM

billybob, that will not fix the problem.  running:

$sqlthing = mysql_query('WHERE newsecid IN (12,34,35,36,37,38,40,41,42,43,45,46,48)') or die(mysql_error());

will yield a syntax EVERYTIME because 'WHERE newsecid IN (12,34,35,36,37,38,40,41,42,43,45,46,48)' is not a complete query.  we appreciate you trying to help, but posting code that is totally erroneous only makes matters worse.

davelinger:  it's because your statement is wrong.  it needs to be an if-elseif-else statement.  as it stands, itll run each if() until it reaches the last if(), which is an if-else.  since the if() condition fails there (because your pid is 12, not 16), it'll run the else{} statement whenever the pid isn't 16, which gives you your problem.

change every if() after the first one to elseif().  alternatively, use a switch() statement:

<?php
switch ($pid)
{
  case 12:
    $sqlthing = 'WHERE newsecid IN (12,34,35,36,37,38,40,41,42,43,45,46,48)';
    break;
  case 13:
    the line for 13;
    break;
  default:
    the WHERE clause to use if none of the cases is matched;
    break;
}
?>


#8 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 15 July 2006 - 03:07 AM

thank you.
http://www.DaveLinger.com
dave at linger dot com

#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 15 July 2006 - 03:27 AM

akitchin so fast beat me there lol......................

dam!

becouse i got beat from speedy here an example ok.

// set a if condition.
if(condition) {

// set a else if condition.
}elseif(condition){

set another elseif condition.
}elseif(condition){

//set another elseif condition.
}elseif(condition){

//finally an else conndition.
}else{

echo" bla bla bla ";

}

please look at the format of else elseif else ok.

good luck.

ps. the speed was the age lol..............
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users