Jump to content

TheTitans

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Everything posted by TheTitans

  1. The web page would show a list of the CDs. Under each CD would be the list of songs (just the name of the songs) that are associated with it. Each song would have a link to its own page to where the lyrics would be displayed. I know how to display the list of CDs. I just need some help with displaying the song names for each CD.
  2. On my web page, I want to display a list of CDs that are associated with each article, and the songs that are associated with each CD. To do this, I have three tables: 1. A table for the CDs 2. A table that has all the songs 3. A table that associates each CD with its song Table cds has columns: id, article_id, name Table songs has columns: id, name, lyrics Table cd_songs has columns: id, cd_id, song_id Now I have a the query that gets the CDs that are associated with each article. $sql = "SELECT cds.id, cds.name, DATE_FORMAT(cds.release_date, '%M %e, %Y') AS formatted_date FROM cds WHERE cds.article_id = '" . $this->id . "'"; But I don't know how to modify the query so that it can also select all the songs for each CD. I'm not sure how to use the JOINs with this, so maybe someone can give me some assistance.
  3. Hello, I have a mysql table: locations: id, color, location, etc I have about 100 rows that have the color of red. I basically want to duplicate those rows but have the color be blue. Is there anything out there that can do this?
  4. Looks like I found the answer to my own problem. I used the sort() function. sort($pics);
  5. I have a script that pulls files from a directory and places the file names into an array. The files are named as 001.jpg, 002.jpg, 003.jpg, etc. The problem is that the files aren't being placed into the array in an orderly way. For example, 409.jpg could be placed in element zero when really 001.jpg should be placed there. How do I fix this? Here is my code: $pics = array(); if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != "Thumbs.db" && $file != "main.jpg") { array_push($pics, $file); } } }
  6. Let's say I have something like this: if (isset($_GET['id']) && $_GET['id'] != '') { // If '?id=' exists in the URL $id = validationCheck($_GET['id']); if ($id) { // do stuff here } } function validationCheck($input) { if (get_magic_quotes_gpc() || get_magic_quotes_runtime()) { $input = stripslashes($input); } $input = mysql_real_escape_string($input); return $input; } Is that function I have good enough to prevent me from SQL injection?
  7. I have a mysql query followed by some html and a while loop <?php // count($versions) is equal to 5 for ($i = 0; $i < count($versions); $i++) { ?> <div id="<?php echo $versions[$i] ?>"> <table> <tr> <td colspan="10" class="dex_header"><strong>Attacks:</strong></td> </tr> <tr> <td style="width:5%; text-align:center">RB</td> <td style="width:10%; text-align:center">Move</td> <td style="width:5%; text-align:center">Type</td> <td style="width:5%; text-align:center">Power</td> <td style="width:5%; text-align:center">Accuracy</td> <td style="width:10%; text-align:center">PP</td> <td style="width:5%; text-align:center">Class</td> <td style="text-align:center">Description</td> </tr> <?php while ($row2 = $db->fetchArray($result3)) { $ver = explode(",", $row2['versions']); if (in_array($versions2[$i], $ver)) { ?> <tr> <td class="dex<?php echo $versions[$i] ?>_sub"><?php echo $row2['level'] ?></td> <td class="dexattack_sub" style="background-color:<?php echo $dex->type_color($row2['type']) ?>"><a href="attacks.php?id=<?php echo $row2['move_id'] ?>"><?php echo $row2['name'] ?></a></td> <td class="dexattack_sub" style="background-color:<?php echo $dex->type_color($row2['type']) ?>"><img src="images/types/<?php echo $row2['type'] ?>.gif" alt="" /></td> <td class="dexattack_sub" style="background-color:<?php echo $dex->type_color($row2['type']) ?>"><?php echo $dex->powerCheck($row2['power']); ?></td> <td class="dexattack_sub" style="background-color:<?php echo $dex->type_color($row2['type']) ?>"><?php echo (($row2['accuracy'] != 0) ? $row2['accuracy'] . '%' : '--' ) ?></td> <td class="dexattack_sub" style="background-color:<?php echo $dex->type_color($row2['type']) ?>"><?php echo $row2['pp'] ?> / <?php echo $dex->calculateMaxPP($row2['pp']) ?></td> <td class="dexattack_sub" style="background-color:<?php echo $dex->type_color($row2['type']) ?>"><img src="images/types/<?php echo $row2['class'] ?>.gif" alt="<?php echo $row2['class'] ?>" title="<?php echo $row2['class'] ?>" /></td> <td class="dexattack_sub" style="background-color:<?php echo $dex->type_color($row2['type']) ?>"><?php echo $row2['blurb_dp'] ?></td> </tr> <?php } // end while loop } ?> </table> </div> <?php // end for loop } ?> The program loops through 5 times. The first time the results are displayed in the proper table format. The second, third, fourth, and fifth time, nothing gets displayed. My theory is that the results from the mysql query have already been looped through once and that's all it can do. Right now the query is outside of the for loop. Everything works if the query is inside the for loop right before the while loop, but that's not good coding practice. So what can I do to fix this?[/code]
  8. I have a script that displays the users who are online at the moment on a website. <?php $online = mysql_query ("SELECT onlineusr FROM online ORDER BY onlineusr ASC"); while ($onlinerow = mysql_fetch_array($online)) { $rank_query = mysql_query("SELECT rank FROM users WHERE usrname = '" . $onlinerow['onlineusr'] . "'"); $row2 = mysql_fetch_array($rank_query); ?> <a href="profile.php?user=<?php echo $onlinerow['onlineusr'] ?>"><span style="color:<?php echo $row2['rank'] ?>"><?php echo $online['onlineusr'] ?></a><br /> <?php } ?> Let's say there are 100 people online. Then there would be 1 query for each user. I think that's too many. What can I do to simplify the amount of queries executed? I've done some research and found out that JOIN and UNION can be used to bring data together. Perhaps I use one of those methods?
  9. I have a pagination system for my website. It works perfectly for my news section. However, I would like to use it for another area of my webite (image gallery). A required id $_GET variable is required for the gallery to work. Because my news section does not required that variable, it is not included when building the link in the createPageNumbers() function. My question is how can I make this work for my image gallery? The class: class Pagination { private $rows_per_page; private $pageno; public function __construct($rows, $page) { $this->rows_per_page = $rows; $this->pageno = $page; } public function pageExists() { if (!isset($this->pageno)) { $this->pageno = 1; } return $this->pageno; } public function integerCheck($lastpage) { $this->pageno = (int)$this->pageno; if ($this->pageno > $lastpage) { $this->pageno = $lastpage; } if ($this->pageno < 1) { $this->pageno = 1; } return $this->pageno; } public function roundFraction($numrows) { return ceil($numrows/$this->rows_per_page); } public function createQuery() { return 'LIMIT ' . ($this->pageno - 1) * $this->rows_per_page .',' . $this->rows_per_page; } public function createPageNumbers($lastpage) { if ($this->pageno == 1) { echo " <<PREV "; } else { $prevpage = $this->pageno - 1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'> <<PREV </a> "; } ?> - <?php for ($i = 1; $i < $lastpage + 1; $i++) { echo '<a href="?pageno=' . $i . '">[' . $i . ']</a> '; } ?> - <?php if ($this->pageno == $lastpage) { echo " NEXT>> "; } else { $nextpage = $this->pageno + 1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT>></a> "; } } } And to use it... include('Pagination.php'); $pagination = new Pagination(10,$_GET['pageno']); $result = $db->query("SELECT count(*) FROM news"); $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; $lastpage = $pagination->roundFraction($numrows); // Checks to make sure $pageno is an integer between 1 and $lastpage $pagination->integerCheck($lastpage); $limit = $pagination->createQuery(); $result2 = $db->query("SELECT * FROM news ORDER BY id DESC $limit"); echo '<p style="text-align:center">'; $pagination->createPageNumbers($lastpage); echo '</p>';
  10. I am currently using the template system here: http://www.massassi.com/php/articles/template_engines/ Right now, I'm currently organizing my website up a bit with this simple system. I was wondering how for loops would work. I did a search and it seems looping is a complicated thing to implement in a template system. I don't want to make this too difficult, so would it be best to just put the for loop and its code in the .tpl page itself? I have a mix of PHP and HTML code in the for loop, which is why I was wondering what I should do.
  11. Found the error; weird error too. if ($value == 0) {} ...That had to be written as: if ($value == "0") {} MrAdam: I know about the foreach statement. The reason why I didn't use it is because there's other code in there. I didn't include it because it was basic HTML and SQL queries that weren't necessary to show.
  12. Yes. for ($i = 0; $i < 1; $i++) { $y2 = explode(",", $x2[$i]); // $y2 is the array that I posted above. The elements 0, Happiness, and Stone are in this array. for ($j = 0; $j < 3; $j++) { // 3 elements in the array; we loop 3 times and display the results. "Basic Form" gets displayed three times, when it should only be displayed once echo $dex->calcEvolutionMethod($y2[$j]) } }
  13. I have an array that is set up like this: Array ( [0] => 0 [1] => Happiness [2] => Stone ) Now I have my function: public function calcEvolutionMethod($value) { if ($value == 0) { return "Basic Form"; } else { return $value; } } Each element in the array is used in the function. "Basic Form" is returned for the first result, which is good; however "Basic Form" is returned for the second and third results too, which is not suppose to happen. Instead, for the second and third result, the else statement needs to kick in and just return "Happiness" and "Stone". I'm not sure what I'm doing wrong.
  14. I have two columns in a mysql table called evo_chain_id and evo_parent_id. They look like this: I would like to check if two or more values in evo_parent_id are the same. If they are, execute one function. If not, execute another function. So, for example, because 265 appears in there more than once, the first function would execute. I think I'm suppose to do something with the SQL COUNT() function, but I'm not too sure how that works. Could some help me?
×
×
  • 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.