Jump to content

iNoob

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Everything posted by iNoob

  1. Hello guys. So I have a pagination that displays games from different categories. For example if I click the 'Skills Games' link, it will display only skill games from my database in the pagination results. However I have noticed that the newer games I add to my database, don't show up first in the list in the pagination results. So I added the fldDate column in my database to add the date the game was added to the database and fetch the date from the new skill games I added to the database by ascending or descending the fldDate column in the pagination results. I am trying to figure out how to fetch the current date of the new games I added and display them first in the pagination once the user clicks on 'Skills Games' link. I have a pagination script that I need to Ascend or Descent depending on the date. This is what I have as query $query = "select distinct fldCategory from games order by fldCategory"; I was thinking maybe to fetch the date by doing this: $query = "select distinct fldCategory from games order by fldCategory ORDER BY fldDate desc"; Would this be correct?
  2. Hello. I am trying to build a PHP hit counter for each game ID in the column of my database when visited, and updating the 'fldPlays' column by +1 to show how many people visited each page. I have a huge table with a list of data, but I'll show just 3 of the columns I have. Here they are: fldID | fldData | fldPlays =================== 32145 Data1 0 21543 Data2 0 75855 Data3 0 36623 Data4 0 12471 Data5 0 =================== I am trying to increase the counter number at the 'fldPlays' column to show how many users had played each game by identifying the ID first. So for example: User types in 'http://www.mysite.com/games.php?id=32145' in the address bar for the 'Data1' game, and then once the user enters that particular page with that ID 32145 as you see in the URL, it adds 1 to the 'fldPlays' in that row. Overall, when I echo out 'fldPlays' as text in each page, it shows how many people actually played that page. Just to let everybody know that I am still learning PHP and I am new to counters as well. My guess to start the PHP counter is to fetch the ID of that URL, you would have to get id like this: <?php if(isset($_GET['id'])) { $conn = mysql_connect("database", "username", "password"); mysql_select_db("data"); $game_id = $_GET['id']; $sql = "SELECT * FROM dbname WHERE fldID='$game_id' LIMIT 1"; ?> If anyone needs clarification, I will reply. Thanks for helping.
  3. This is my pagination with the number bar: <?php $page = $_GET['page']; $category = $_GET['cat']; $your_db = @ new mysqli("$hostname","$username", "$password"); if (mysqli_connect_errno()) { echo 'ERROR!<br />'.mysqli_connect_errno() .' - Not connected : '.mysqli_connect_error().'<br />'; die; } else { $db_connect = $your_db->select_db("database"); if (!$db_connect) { echo 'Error!'; die; } } echo '<p>'; $query = "select distinct fldCategory from tablename order by fldCategory"; $result = $your_db->query($query); $number_of_records = $result->num_rows; for ($i = 0; $i < $number_of_records; $i++) { $row = $result->fetch_assoc(); echo '<a href="page_name.php?cat='.stripslashes($row['fldCategory']).'">'; echo stripslashes($row['fldCategory']); echo '</a> / '; } echo '</p>'; if ($category) { $query = "select fldID, fldTitle, fldCategory, fldIconMedium, fldLink from tablename where fldCategory = '$category' order by fldCategory"; } else { $query = "select fldID, fldTitle, fldCategory, fldIconMedium, fldLink from tablename order by fldCategory"; } $result = $your_db->query($query); $number_of_records = $result->num_rows; $num_pages = $number_of_records / 7; if (($number_of_records % 7) > 0 ) { $num_pages++; } if (strlen($page) == 0) { $page = 0; } else { $page = $page * 7; } echo '<table border="1">'; $row_num = 1; $result->data_seek($page); for ($i = $page; $i < $number_of_records; $i++) { if ($row_num <= 7) { echo '<tr>'; for ($col_num = 0; $col_num < 5; $col_num++) { $row = $result->fetch_assoc(); echo '<td>'; show_image(stripslashes($row['fldIconMedium']),stripslashes($row['fldTitle'])); echo '<br />'; echo '<a href="'.stripslashes($row['fldLink']).'" target="_blank">'; echo stripslashes($row['fldTitle']); echo '</a>'; echo '</td>'; } $row_num++; echo '</tr>'; } else { break; } } echo '</table>'; for ($j = 0; $j < $num_pages; $j++) { $page_link = $j + 1; echo '<a href="page_name.php?page='.$j.'&cat='.$category.'">'.$page_link.'</a> '; } echo ' '.$number_of_records; function show_image($image_name, $alt) { if (file_exists("path_to_images/$image_name")) { $dim_img = getimagesize('path_to_images/'.$image_name); echo '<img src="path_to_images/'.$image_name.'" alt = '.$alt.' border=0 align="bottom"'; echo 'width = '. $dim_img[0] .' height = ' .$dim_img[1] . ' />'; } else echo 'NO IMAGE'; } ?> To see it in action, here is the link to the 'skill games' section of the pagination script: http://netroxy.com/games2.php?cat=skills Ok here is the issue 1. As you can see, all the results displayed in the pagination script is correct, but what confuses me is the extra blank images that continue on in the table of the pagination table. I tried replacing the queries to see if the extra blank images would be removed like this: $query = "select fldID, fldTitle, fldCategory, fldIconMedium, fldLink from tablename where fldCategory = '$category' and length(fldIconMedium) > 0 order by fldCategory"; } else { $query = "select fldID, fldTitle, fldCategory, fldIconMedium, fldLink where length(fldIconMedium) > 0 from tablename order by fldCategory"; So you see, I used 'length(fldIconMedium) > 0' making images less than 0 to see if the rest of the blank images would disappear from the cells in the table. This has not worked. Hence 'fldIconMedium' is the column for the images in the mysql database. Visit the link and you'll see the extra blank images through the results. This also applies when search for other game categories, blank images appear and I cant remove those extra blank images from the table.
×
×
  • 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.