-7

I'm using a while loop and pagination to filter records. I want to add a dropdown to the loop to make it easier for visitors to browse records. I've debugged and there are no errors but the fetch array isn't working, I don't get any data. The join is necessary to pair form and image data, I store and retrieve the path to images which are uploaded into a folder.

<?php
session_start();
include "connect.php";
error_reporting(E_ERROR);
//select records from two tables and loop through results
$result = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id ORDER BY tcgcomics.id");
$count = mysql_num_rows($result);
while($row = mysql_fetch_array($result)){
$tcgname[]= $row['name'];
$tcgintelligence[]= $row['intelligence'];
$tcgstrength[]= $row['strength'];
$tcgspeed[]= $row['speed'];
$tcgenergy[]= $row['energy'];
$tcgfighting[]= $row['fighting']; 
$tcggoogle[]= $row['google']; 
$tcgbiography[]= $row['biography'];
$img_paths[] = $row["path"];

//filter records via dropown

if(isset($_POST['Filter'])){
if($_POST['value'] == 'Apocalypse'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Apocalypse' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Black Adam'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Black Adam' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Darkseid'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Darksied' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Doomsday'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Doomsday' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Gladiator'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Gladiator' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Mongul'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Mongul' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Hulk'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Hulk' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Hyperion') {$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Hyperion' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Thanos'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Thanos' ORDER BY tcgcomics.id;");}
elseif($_POST['value'] == 'Ultron'){$query = mysql_query("SELECT * FROM tcgcomics JOIN tcgcomicsimages ON tcgcomics.id = tcgcomicsimages.id WHERE name='Ultron' ORDER BY tcgcomics.id;");}
else{

//pagination
if(empty($_GET['page'])){
    $i = $count - 1;
$current = $count;
}else{
$i = $_GET['page'];
$current = $i;
$i = $i - 1;
}
if($i == 0 && $count == 1){
    $prevlink = "";
    $next = $current + 1;
    $nextlink = "";
}elseif($i == 0 && $count > 1){
    $prevlink = "";
    $next = $current + 1;
    $nextlink = "<a href='?page=$next'>Next</a>";
}elseif($current > 0 && $current < $count){
    $prev = $current - 1;
    $next = $current + 1;
    $prevlink = "<a href='?page=$prev'>Previous</a>";
    $nextlink = "<a href='?page=$next'>Next</a>"; 
}elseif($current == $count){
    $prev = $current - 1;
    $prevlink = "<a href='?page=$prev'>Previous</a>";
    $nextlink = "";
}
}
}
}
?>
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
raybarone
  • 31
  • 1
  • 2
  • 7
  • possible duplicate of [What is unexpected T\_VARIABLE in PHP?](http://stackoverflow.com/questions/1464919/what-is-unexpected-t-variable-in-php) – Rick S May 31 '14 at 21:13
  • 1
    It’s a simple missing semicolon in the line previous to the one the error message mentions … If you know that little about the syntax, that you can not even figure something this trivial out yourself, then please a) stop b*tching about totally justified downvotes, and b) learn some effing basics _before_ you meddle with stuff like this. – CBroe May 31 '14 at 21:13
  • I've added a semi-colon. Now I get unexpected end. And you don't learn if you don't meddle. – raybarone May 31 '14 at 21:17
  • Well then go _learn_ how to count curly braces … and from now on, indent your code _properly_ to avoid problems like this. – CBroe May 31 '14 at 21:24

1 Answers1

0

Check line 6: You need a semicolon at the end.

ALso you have unneeded semi-colons in all your query statements. in mysql_query you don't need them.

e.g. change mysql_query("SELECT * from tcgcomics WHERE name='Apocalypse';"); to mysql_query("SELECT * from tcgcomics WHERE name='Apocalypse'");

Rob
  • 214
  • 1
  • 5
  • Thanks. I have an uneven number of { braces. Do I need to add another condition? – raybarone May 31 '14 at 21:47
  • No, you need to add another curly brace. – CBroe May 31 '14 at 21:49
  • I used http://phpcodechecker.com to break down the code and eliminate the errors. I added more braces but the while fetch array doesn't fetch any data so there's something wrong with the dropdown. The code worked fine before I added the dropdown. So it wasn't just a case of a missing semi-colon or missing braces. – raybarone May 31 '14 at 22:22
  • Well, messing with existing code with insufficient knowledge of the overall basics does of course have the potential to lead to further problems … so now you will have to do some _debugging_. – CBroe May 31 '14 at 22:32
  • I know the basics. Users can add, edit and delete records but I've only worked with dropdowns this week and wanted them to run on post which I managed to do with help from a member here. The queries fire in phpmyadmin so I know there is no issue there. Yes I should have checked the syntax errors more carefully. – raybarone May 31 '14 at 23:14