Jump to content

WHERE column IN (value,value) problem


DaveLinger

Recommended Posts

heres the code:

[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++;
}
}
?>
[/code]

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

No errors, but no results, from ANY of the values specified!
Link to comment
https://forums.phpfreaks.com/topic/14641-where-column-in-valuevalue-problem/
Share on other sites

[code]
<?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++;
}
}
?>
[/code]
billybob, that will not fix the problem.  running:

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

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:

[code]<?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;
}
?>[/code]
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..............

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.