Jump to content

FlashNinja

Members
  • Posts

    32
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

FlashNinja's Achievements

Member

Member (2/5)

0

Reputation

  1. I've tidied it up - getting rid of unused tags and such - but the problem still persists. Here's the new code: <?php include 'connect.php'; session_start(); $games = mysql_query("SELECT * FROM games ORDER BY id DESC LIMIT 5") or die(mysql_error()); $numRows = mysql_num_rows($games); ?> <html> <head> <title> Game-On </title> <link href="game.css" type="text/css" rel="stylesheet"> </head> <div id ='body1'> <div id ='headm'> <a style = 'text-decoration:none' href ='index.php'>Home</a> | <a style = 'text-decoration:none' href ='about.php'> About</a> | <a style = 'text-decoration:none' href ='support.php'> Support</a> </div> <div id = 'banner'> <div id = 'logo'><a style="text-decoration:none" href='index.php'> <h1>Game-on</h1> </a></div> <div id='basket'> You have <?php if(empty($_SESSION['id'])) { echo "0"; } else { $uid = $_SESSION['id']; $sql = "SELECT * FROM basket WHERE session = '$uid'"; $basket = mysql_query($sql) or die (mysql_error()); $numrows = mysql_num_rows($basket); echo $numrows; } ?> items in your basket </div> <div id='bbutton'> <ul><li><a href='basket.php'>Basket</a></li></ul> </div> <form id="search" class = 'form' action="search.php?page=" enctype="multipart/form-data" method="post"> <input type="text" id="search" name = "search" tabindex="1"/> <input type ='submit' class = 'submit' name ='Search' value ='Search' /> </form> </div> <div id ='body2'> <div id ='bmenu'> <h2>Consoles:</h2> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=Xbox 360&cat='>Xbox 360</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=PS3&cat='>PS3</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=Nintendo Wii&cat='>Nintendo Wii</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=Nintendo 3DS&cat='>Nintendo 3DS</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=PS Vita&cat='>PS Vita</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=Nintendo DS&cat='>Nintendo DS</a> <br> <br> <br> <h2>Categories:</h2> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=&cat=Action'>Action</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=&cat=Adventure'>Adventure</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=&cat=Fighting'>Fighting</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=&cat=Horror'>Horror</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=&cat=Puzzle'>Puzzle</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=&cat=Racing'>Racing</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=&cat=Role Playing'>Role Playing</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=&cat=Shooter'>Shooter</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=&cat=Sport'>Sport</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=&cat=Strategy'>Strategy</a> <br> </div> <div id ='gtext'> <h1>Welcome to Game-On.</h1> </div> <div id = 'ngames'> Recently Added Games: <br> <br> </div> <div id = 'gametableg'> <?php for($count = 1; $count <= $numRows; $count++) { $game = mysql_fetch_array($games); $img = $game['img']; $name = $game['name']; $id = $game['id']; $stock = $game['stock']; if( $stock == 0) { $instock = "Out of stock"; } else { $instock = "In stock"; } echo "<div class = 'block'>"; echo "<a href=game_page.php?game=" . $id . ">" . $name . "</a>"; echo "<br>"; echo "<br>"; echo "<div class = 'price'>"; echo "Only ?".$game['price']; echo "</div>"; echo "<div class = 'stock'>"; echo $instock; echo "</div>"; echo "<div class = 'img'>"; echo "<a href=game_page.php?game=" . $id . "><img src = '$img'></a>"; echo "</div>"; echo "<div class = 'basketb'>"; echo "<ul><li><a href = 'basket_check.php?id=". $id ."'>Add to basket</a></li></ul>"; echo "</div>"; echo "<br>"; echo "<br>"; echo "</div>"; echo "<br>"; } echo "</div>"; echo "</div>"; echo "</div>"; ?> <footer> Game-On is a student project and not an actual e-commerce website. Please do not submit any payment details to the website. </footer> </html> I'm going to continue to try and solve this, but hopefully someone here has a clue what's wrong here.
  2. So I'm producing a number of results in a for loop. There results are displayed on the site and should stay on the 'page'. E.G. <div = 'body'> 'For loop' "Results" 'End of For loop' </div> The problem I'm having here is that when more than 2 or 3 results are produced from this For loop the results actually start moving off of the page. E.G. < div id = 'body> 'For loop' 'Result' 'Result' </div> 'Result' 'Result' 'End of For loop' Could someone take a look at this code and figure out why this is happening, please. I'm stumped. <?php include 'connect.php'; session_start(); if(empty($_GET['page'])) { $page = 1; } else { $page = $_GET['page']; } $start_from = ($page -1) * 10; $end = $page * 10; if (empty($_GET['con'])) { $cat = $_GET['cat']; $cat = stripslashes($cat); $cat = trim($cat); $cat = mysql_real_escape_string($cat); $games = mysql_query("SELECT * FROM games WHERE catagory = '$cat' ORDER BY id DESC LIMIT $start_from, $end") or die(mysql_error()); $numRows = mysql_num_rows($games); } else { $con = $_GET['con']; $con = stripslashes($con); $con = trim($con); $con = mysql_real_escape_string($con); $games = mysql_query("SELECT * FROM games WHERE console = '$con' ORDER BY id DESC LIMIT $start_from, $end") or die(mysql_error()); $numRows = mysql_num_rows($games); } if(empty($_GET['con']) || (empty($_GET['cat']))) { } else { $con = $_GET['con']; $con = stripslashes($con); $con = trim($con); $con = mysql_real_escape_string($con); $cat = $_GET['cat']; $cat = stripslashes($cat); $cat = trim($cat); $cat = mysql_real_escape_string($cat); $games = mysql_query("SELECT * FROM games WHERE console ='$con' AND catagory = '$cat' ORDER BY id DESC LIMIT $start_from, $end") or die(mysql_error()); $numRows = mysql_num_rows($games); } ?> <html> <link href="game.css" type="text/css" rel="stylesheet"/> <div id ='body1'> <div id ='headm'> <a style = 'text-decoration:none' href ='index.php'>Home</a> | <a style = 'text-decoration:none' href ='about.php'> About</a> | <a style = 'text-decoration:none' href ='support.php'> Support</a> </div> <div id = 'banner'> <div id = 'logo'><a style="text-decoration:none" href='index.php'> <h1>Game-on</h1> </a></div> <div id='basket'> You have <?php if(empty($_SESSION['id'])) { echo "0"; } else { $uid = $_SESSION['id']; $sql = "SELECT * FROM basket WHERE session = '$uid'"; $basket = mysql_query($sql) or die (mysql_error()); $numrows = mysql_num_rows($basket); echo $numrows; } ?> items in your basket </div> <div id='bbutton'> <ul><li><a href='basket.php'>Basket</a></li><ul> </div> <div id ='search'> <form id="search" class = 'form' action="search.php?page=" enctype="multipart/form-data" method="post"> <input type="text" id="search" name = "search" tabindex="1"/> <input type ='submit' class = 'submit' name ='Search' value ='Search' /> </form> </div> </div> <div id ='body2'> <div id ='bmenu'> Filter: <br> <?php if(empty($_GET['con'])) { echo 'Console: '; } else { echo 'Console: '.$_GET['con']; } ?> <br> <?php if(empty($_GET['cat'])) { echo 'Category: '; } else { echo 'Category: '.$_GET['cat']; } ?> <br> <br> <h2>Consoles:</h2> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=Xbox 360&cat=<?php if(isset($_GET['cat'])){ echo $_GET['cat'];}?>'>Xbox 360</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=PS3&cat=<?php if(isset($_GET['cat'])){ echo $_GET['cat'];}?>'>PS3</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=Nintendo Wii&cat=<?php if(isset($_GET['cat'])){ echo $_GET['cat'];}?>'>Nintendo Wii</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=Nintendo 3DS&cat=<?php if(isset($_GET['cat'])){ echo $_GET['cat'];}?>'>Nintendo 3DS</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=PS Vita&cat=<?php if(isset($_GET['cat'])){ echo $_GET['cat'];}?>'>PS Vita</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=Nintendo DS&cat=<?php if(isset($_GET['cat'])){ echo $_GET['cat'];}?>'>Nintendo DS</a> <br> <br> <br> <h2>Categories:</h2> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=<?php if(isset($_GET['con'])){ echo $_GET['con'];}?>&cat=Action'>Action</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=<?php if(isset($_GET['con'])){ echo $_GET['con'];}?>&cat=Adventure'>Adventure</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=<?php if(isset($_GET['con'])){ echo $_GET['con'];}?>&cat=Fighting'>Fighting</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=<?php if(isset($_GET['con'])){ echo $_GET['con'];}?>&cat=Horror'>Horror</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=<?php if(isset($_GET['con'])){ echo $_GET['con'];}?>&cat=Puzzle'>Puzzle</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=<?php if(isset($_GET['con'])){ echo $_GET['con'];}?>&cat=Racing'>Racing</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=<?php if(isset($_GET['con'])){ echo $_GET['con'];}?>&cat=Role Playing'>Role Playing</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=<?php if(isset($_GET['con'])){ echo $_GET['con'];}?>&cat=Shooter'>Shooter</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=<?php if(isset($_GET['con'])){ echo $_GET['con'];}?>&cat=Sport'>Sport</a> <br> <a style = 'text-decoration:none' href='game_cat.php?page=&con=<?php if(isset($_GET['con'])){ echo $_GET['con'];}?>&cat=Strategy'>Strategy</a> <br> </div> <div id ='gctext'> <h1> Games </h1> </div> <?php for($count = 1; $count <= $numRows; $count++) { $game = mysql_fetch_array($games); $img = $game['img']; $name = $game['name']; $id = $game['id']; $stock = $game['stock']; if( $stock == 0) { $instock = "Out of stock"; } else { $instock = "In stock"; } ?> <div id = "gametable"> <div id = 'block'> <a href='game_page.php?game=<?php echo $id; ?>'><? echo $name; ?></a> <br> <br> <div id = 'price'> Only ?<?php echo $game['price']; ?> </div> <div id = 'stock'> <?php echo $instock; ?> </div> <div id = 'img' > <a href='game_page.php?game=<? echo $id; ?>'><img src = '<?php echo $img; ?>'></a> </div> <div id = 'basketb'> <ul><li><a href = 'basket_check.php?id=<? echo $id;?>'>Add to basket</a></li></ul> </div> <br> <br> </div> <br> </div> <?php } ?> <br> <table> <?php if(empty($_GET['cat'])){ $con = $_GET['con']; $con = stripslashes($con); $con = trim($con); $con = mysql_real_escape_string($con); $pgsql = "SELECT COUNT(name) FROM games WHERE console = '$con'"; $pgresult = mysql_query($pgsql); $pgrow = mysql_fetch_row($pgresult); $totalrec = $pgrow[0]; $totalpg = ceil($totalrec / 10); for( $i=1; $i<=$totalpg; $i++) { echo "<a href ='member_list.php?page=".$i."'>".$i."</a>"; } } else { $cat = $_GET['cat']; $cat = stripslashes($cat); $cat = trim($cat); $cat = mysql_real_escape_string($cat); $pgsql = "SELECT COUNT(name) FROM games WHERE catagory = '$cat'"; $pgresult = mysql_query($pgsql); $pgrow = mysql_fetch_row($pgresult); $totalrec = $pgrow[0]; $totalpg = ceil($totalrec / 10); for( $i=1; $i<=$totalpg; $i++) { echo "<a href ='game_cat.php?page=".$i."'>".$i."</a>"; } } ?> </table> </div> </div> </div> <footer> Game-On is a student project and not an actual e-commerce website. Please do not submit any payment details to the website. </footer> </html> P.S. Sorry for the crude 'diagrams' of my issue. Hopefully you understand my issue.
  3. It lives! Thanks for the help, although I'm now curious to know what exactly the LEFT JOIN function in that SQL query does.
  4. I'm actually only obtaining the name of the item and the price of the item. So two columns. I wildcarded it due to habit. I'm displaying both the name of the item and it's price, and I need to add together each price variable echoed by the FOR loop.
  5. So I'm coding together a basket/cart for an e-commerce site. I have the contents of the basket being echoed out in a FOR loop, including the price of each item. I'm not sure though how to exactly add together all of the basket item prices together while they are in a FOR loop in order to produce a total sum for the basket contents. Could anyone give me some pointers? Here's the FOR loop: $uid = $_SESSION['id']; $sql = "SELECT * FROM basket WHERE session = '$uid'"; $basket = mysql_query($sql) or die (mysql_error()); $numrows = mysql_num_rows($basket); for($count = 1; $count <= $numrows; $count++) { $baskets = mysql_fetch_array($basket); $bid = $baskets['contents']; $sql2 = "SELECT * FROM games WHERE id = '$bid'"; $item = mysql_query($sql2) or die (mysql_error()); $items = mysql_fetch_array($item); $name = $items['name']; $gid = $items['id']; echo "<div id = 'strip'>"; echo "<a href=game_page.php?game=" . $gid . ">" . $name . "</a>"; echo "</div>"; echo "<div id = 'basprice'>"; echo "Price: ?".$items['price']; echo "</div>"; echo "<br>"; echo "<br>"; echo "<br>"; }
  6. So I have a little problem here. I'm trying to put a limit on an SQL Query, simple. The problem that is arising is that the variables I am using to denote the limit values are causing some funky MySQL syntax error. This is the error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''0','20'' at line 1 Here's the snippet of code that appears to be causing the error. The variables being used for the limit are the values I expect them to be so that doesn't seem to be the issue here. if(isset($_GET['page'])) { $page = $_GET['page']; } else { $page = 1; } $start_from = ($page-1) * 20; $end = $page * 20; $ads = mysql_query("SELECT * FROM ad WHERE usr ='$member' ORDER BY id DESC LIMIT '$start_from','$end'") or die(mysql_error()); $numRowsa = mysql_num_rows($ads);
  7. I've worked on it a bit more and the FOR loop has stopped looping for infinitly, the problem that has arose now is that it's producing the number of results that it should be but all the results are duplicates of the newest results relating to the query. For example: The table contains two results relating to the user Abed, the reviews are both by Jeff one reads "yes" the other reads "no" - the "no" review is the newest entry. As there are two results related to Abed two results are produced by the FOR loop, but both of them read "no" when one should read "yes" and the other should read "no". Can someone help me with this issue? PHP: <div = "reviews"> <?php $sqlrev = "SELECT * FROM rev WHERE rev_name = '$member' ORDER BY id DESC"; $revresult = mysql_query($sqlrev) or die(mysql_error()); $revrows = mysql_num_rows($revresult); $revname = mysql_fetch_array($revresult); ?> User reviews for <? echo $member;?> <br> <br> <table border="0"> <?php for($count = 1; $count <= $revrows; $count++) { ?> <tr> <?php echo "Review by: " . $revname['usr_name']; echo "<br>"; echo $revname['text'] ."<br>"; echo "<br>"; ?> </tr> <?php } ?> </table> </div>
  8. I've echoed them outside the FOR loop and within it. Outside of it they echo as they should - 1, ARRAY - but trying to echo them within the FOR loop causes an infinite loop still. It seems to be the requirements for the loop to start that is causing this infinite loop, the wierd thing is that the other FOR loops I've used have had the same requirements.
  9. I did that, still having the same issue. It just keeps repeating until the browser crashes. It's really wierd none of my other FOR loops are doing this and this one is entirely baed off of the functioning ones.
  10. I've develped this small script to display user reviews stored in a my databases review table. The problem with the script though is that it seems to be looping ad nauseum. The wierd thing though, is that I've used a very similair script to display another list of items on this site, and it worked correctly without any issue. Could someone take a look at this for me and diagnose the error with the script. The SQL table: CREATE TABLE IF NOT EXISTS `rev` ( `id` int(11) NOT NULL AUTO_INCREMENT, `rev_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, `usr_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, `text` varchar(600) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; The PHP script: User reviews for <? echo $member;?> <br> <table border="0"> <?php for($count = 1; $count <= $revrows; $count++) { $sqlrev = "SELECT * FROM rev WHERE rev_name = '$member' ORDER BY id DESC"; $revresult = mysql_query($sqlrev) or die(mysql_error()); $revrows = mysql_fetch_row($revresult); $revname = mysql_fetch_array($revresult); ?> <tr> <?php print "Review by: " . $revname['usr_name'] . "<br>". $revname['text']; ?> </tr> <?php } ?> </table>
  11. Is there any other way you can think of producing a non linear search in SQL? I was previously using LIKE to take the search entry from php and run it through the LIKE query but it only read tags in a linear fashion. For example: Two entries in the database Row 1: 'dragon', 'roost' Row 2: 'dragon', 'island' 'roost' Entering a search term for 'dragon' produces both those results, but entering the search term 'dragon roost' will only produce the first row. Is there any method that will allow me to have both rows appear if a user enters two tags that match into the search?
  12. Now I'm developing a search engine for my site, which of course requires databases. I'm using FULL TEXT to search my database and return the results. Here's the query I'm using: "SELECT * FROM tag WHERE MATCH ( name, tag1, tag2, tag3, tag4, tag5 ) AGAINST ('dragon')"; And here's the SQL table: CREATE TABLE IF NOT EXISTS `tag` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, `tag1` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, `tag2` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, `tag3` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, `tag4` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, `tag5` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, PRIMARY KEY (`id`), KEY `name` (`name`), FULLTEXT KEY `name_2` (`name`,`tag1`,`tag2`,`tag3`,`tag4`,`tag5`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; -- -- Dumping data for table `tag` -- INSERT INTO `tag` (`id`, `name`, `tag1`, `tag2`, `tag3`, `tag4`, `tag5`) VALUES (1, 'Dave', 'dragon', 'roost', '', '', ''), (2, 'Dave2', 'dragon', 'island', 'roost', '', ''); When using the query above to search for 'dragon' in the database I'm expecting the query to return any rows that contain 'dragon', but this is not the case. The query returns nothing, when to my knowledge it should be returning both rows currently in the database. What is it that I have done incorrectly here and is preventing me getting the results I want?
  13. After trying your code with no additional tweaks by myself, it actually works fine. I thought I had already checked that, but I guess I was mistaken. Thank you for the help!
  14. I've narrowed down what seems to be the problem with my search script. PHP code: $ad_data = "Results for: " .$search."<br>"; $x = 0; $ads = mysql_fetch_array($result); $rows = mysql_num_rows($result); while($ads = mysql_fetch_array($result) && $x <= $rows) Removing the "$x <= $rows" part of the requirements for the while loop to run, makes it actually run. Can anyone see why this is an issue?
  15. Took a look at your amendements and fixed my code, but it's still not working as it should. No results are being produced where there shou;d be results. Updated code: <?php include 'connect.php'; session_start(); $_SESSION['username']; if(!(isset($_SESSION['login']) && $_SESSION['login']!= " ")){ header("Location: login.php"); } $username = $_SESSION['username']; $tablename = 'ad'; $search = trim(stripslashes($_POST['search'])); $searchSQL = mysql_real_escape_string($search); if (empty($search)) { header("Location:search_err.php"); } else $sql = "SELECT * FROM $tablename WHERE `name` LIKE '%{$searchSQL}%' OR `tags` LIKE '%{$searchSQL}%'"; $result = mysql_query($sql) or die (mysql_error()); $ad_data = "Results for: {$search}<br>\n"; if (mysql_num_rows($result) <1) { header("Location:search_err.php"); } else $ad_data = "Results for: " .$search.""; $x=1; $ads = mysql_fetch_array($result); while($ads = mysql_fetch_array($result) && $x <= mysql_num_rows($result)) { $ad_name = $ads['name']; $ad_tags = $ads['tags']; if(stristr($ad_name, $search)) { $ad_data .= "<a href = ad_page.php>". $ad_name ."</a>"; $xi=1; } else { $xi=0; } if(isset($xi) && $xi == 1) { $ad_tags_exp = explode(',',$ad_tags); $fi = 0; while($fi = 0) { if($ad_tags_exp[$fi] == $search) { $fi = 1; $ad_data .= "<a href = ad_page.php>". $ad_name ."</a>"; } } } $x++; } echo $ad_data; ?>
×
×
  • 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.