PHP Database Code
Posted: Fri Jul 08, 2011 5:25 am
Hello All,
I need a bit opf guidance with a peice of my code. I have been designing a website for the past couple of months and i am now at the clean up stage. I am have some frustration with a snippet of code i am trying to simply. Here is the code;
$sqlCommand = "SELECT pagetitle FROM games WHERE category='action'";
$query = mysqli_query($myConnection, $sqlCommand & ' LIMIT 39') or die(mysqli_error($myConnection));
$query2 = mysqli_query($myConnection, $sqlCommand &' LIMIT 80,119') or die(mysqli_error($myConnection));
$query3 = mysqli_query($myConnection, $sqlCommand &' LIMIT 80,119') or die(mysqli_error($myConnection));
$query4 = mysqli_query($myConnection, $sqlCommand &' LIMIT 120, 159') or die(mysqli_error($myConnection));
//List A-Z 1---------------------------------------------
$menusystem = '';
while ($row = mysqli_fetch_array($query)) {
$pagetitle = $row["pagetitle"];
$menusystem .= '<a href="Play.php?Game=' . $pagetitle . '">' . $pagetitle . '</a></br>';
}
mysqli_free_result($query);
//List A-Z 2---------------------------------------------
$menusystemB = '';
while ($row = mysqli_fetch_array($query2)) {
$pagetitle = $row["pagetitle"];
$menusystemB .= '<a href="Play.php?Game=' . $pagetitle . '">' . $pagetitle . '</a></br>';
}
mysqli_free_result($query2);
//List A-Z 3---------------------------------------------
$menusystemC = '';
while ($row = mysqli_fetch_array($query3)) {
$pagetitle = $row["pagetitle"];
$menusystemC .= '<a href="Play.php?Game=' . $pagetitle . '">' . $pagetitle . '</a></br>';
}
mysqli_free_result($query3);
//List A-Z 4---------------------------------------------
$menusystemD = '';
while ($row = mysqli_fetch_array($query4)) {
$pagetitle = $row["pagetitle"];
$menusystemD .= '<a href="Play.php?Game=' . $pagetitle . '">' . $pagetitle . '</a></br>';
}
mysqli_free_result($query4);
As you can see its very simple, i have 4 menus each displaying 40 values (lists basically). What i am trying to acheive is using the $sqlcommand values i want to add on the limit in the $query. For example $sqlcommand line and the add the limit on the end, "SELECT pagetitle FROM games WHERE category='action' LIMIT ??". Its obviously the & "LIMIT ??" on each $query thats the problem.
Ay suggestions would be fantastic
regards
I need a bit opf guidance with a peice of my code. I have been designing a website for the past couple of months and i am now at the clean up stage. I am have some frustration with a snippet of code i am trying to simply. Here is the code;
$sqlCommand = "SELECT pagetitle FROM games WHERE category='action'";
$query = mysqli_query($myConnection, $sqlCommand & ' LIMIT 39') or die(mysqli_error($myConnection));
$query2 = mysqli_query($myConnection, $sqlCommand &' LIMIT 80,119') or die(mysqli_error($myConnection));
$query3 = mysqli_query($myConnection, $sqlCommand &' LIMIT 80,119') or die(mysqli_error($myConnection));
$query4 = mysqli_query($myConnection, $sqlCommand &' LIMIT 120, 159') or die(mysqli_error($myConnection));
//List A-Z 1---------------------------------------------
$menusystem = '';
while ($row = mysqli_fetch_array($query)) {
$pagetitle = $row["pagetitle"];
$menusystem .= '<a href="Play.php?Game=' . $pagetitle . '">' . $pagetitle . '</a></br>';
}
mysqli_free_result($query);
//List A-Z 2---------------------------------------------
$menusystemB = '';
while ($row = mysqli_fetch_array($query2)) {
$pagetitle = $row["pagetitle"];
$menusystemB .= '<a href="Play.php?Game=' . $pagetitle . '">' . $pagetitle . '</a></br>';
}
mysqli_free_result($query2);
//List A-Z 3---------------------------------------------
$menusystemC = '';
while ($row = mysqli_fetch_array($query3)) {
$pagetitle = $row["pagetitle"];
$menusystemC .= '<a href="Play.php?Game=' . $pagetitle . '">' . $pagetitle . '</a></br>';
}
mysqli_free_result($query3);
//List A-Z 4---------------------------------------------
$menusystemD = '';
while ($row = mysqli_fetch_array($query4)) {
$pagetitle = $row["pagetitle"];
$menusystemD .= '<a href="Play.php?Game=' . $pagetitle . '">' . $pagetitle . '</a></br>';
}
mysqli_free_result($query4);
As you can see its very simple, i have 4 menus each displaying 40 values (lists basically). What i am trying to acheive is using the $sqlcommand values i want to add on the limit in the $query. For example $sqlcommand line and the add the limit on the end, "SELECT pagetitle FROM games WHERE category='action' LIMIT ??". Its obviously the & "LIMIT ??" on each $query thats the problem.
Ay suggestions would be fantastic
regards