Jump to content

Levr0x0rz

Members
  • Posts

    7
  • Joined

  • Last visited

Levr0x0rz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you for your comments. Should there be an alternative way to achieve what I am trying to do, rather than switch statements? I considered using if-statements, and was told switches are a preferred method. I'm working on a db driven site for an online gaming team, so such switches or if statements will be used everywhere, to allow different content to be displayed on the same page (eg. roster.php?id=10 and roster.php?status=active&recruit=no), for example. Jon Aspiring Web Developer @JonEdney1
  2. Hello, I've been posting a lot, ensure I'm looking things up and reading around before I post something. I'm trying to execute a SQL statement, using $_GET['var']. It's just not working at all, and I was wondering if someone could shine some light on this for me. With this below code, I'm aiming to have a structure such as news.php?id=1 (where 1 would be the news_id of the row). Manually going to the news.php?id=1 pulls proper content, but when there is no id specified, or it does not exist, nothing is displayed. <?php $id = isset($_GET['id'])?$_GET['id']:null; switch ($id) { case $id: $sql = "SELECT * FROM news WHERE news_id = '$id'"; if(!$result = $db->query($sql)) { die('There was a problem running the query. [' . $db->error . ']'); } while($row = $result->fetch_assoc()) { ?> <table class="content"> <tr> <td class="content_header"><a href="news.php?id=<?php echo $row['news_id']; ?>"><?php echo $row['title']; ?></td> </tr> <tr> <td class="content_highlight">Posted by <a href="roster.php?id=<?php echo $row['roster_id']; ?>">-VoW- <?php echo $row['author']; ?></a> on <?php echo $row['date']; ?></td> </tr> <tr> <td class="content_data"><?php echo $row['content']; ?></td> </tr> </table><br /> <?php } break; default: $sql = "SELECT * FROM news"; if(!$result = $db->query($sql)) { die('There was a problem running the query. [' . $db->error . ']'); } while($row = $result->fetch_assoc()) { ?> <table class="content"> <tr> <td class="content_header"><a href="news.php?id=<?php echo $row['news_id']; ?>"><?php echo $row['title']; ?></td> </tr> <tr> <td class="content_highlight">Posted by <a href="roster.php?id=<?php echo $row['roster_id']; ?>">-VoW- <?php echo $row['author']; ?></a> on <?php echo $row['date']; ?></td> </tr> <tr> <td class="content_data"><?php echo $row['content']; ?></td> </tr> </table><br /> <?php } } ?> As you can see from above, for the id queries, I'm pulling a table to display only that particular query, where if there is no id being queried, or it doesn't exist (default case), I'm displaying all news. Jon Aspiring Web Developer @JonEdney1
  3. Change line 23 back to this: $sql="SELECT * FROM laptop_products WHERE product_id = '".$q."'"; Them, where you have the variable q set, set it this way: $q = isset($_GET['q'])?$_GET['q']:null; Let me know if that gets things moving. Jon Aspiring Web Developer @JonEdney1
  4. Hi kicken, Thank you for the tip, it worked like a charm. While my memory may be off, I don't recall doing this back about 5-6 years ago, is this something new? Jon Aspiring Web Developer @JonEdney1
  5. Try this: $sql="SELECT * FROM laptop_products WHERE product_id = = '{$q}'"; Jon Aspiring Web Developer @JonEdney1
  6. Hello, Getting back into web development, I'm finding myself quire removed from what I once remember. I"ve recently updated the PHP/MySQL association coding with mysqli instead of mysql as I see that is a way things are heading. In a nut shell, I'm going through Lynda.com training videos on PHP, but I'm working on a mock website on the side, where I'm trying to put a fully functioning site together. I've done it before, but for the life of me my memory is not what it used to be. This "mock site" is a gaming team website (helps keep interest, I enjoy gaming). I'm looking to make the site off 5 primary pages: index about matches roster news From there, I want to create the pages dynamically (eg. roster.php?id=10) and it would display content for whomever id 10 is in the roster table. Easy stuff, I thought. I've looked into using switch statements to do this, but I cannot get the $_GET['id'] to read in the coding, so the URL will pull the proper content. My structure looks like this: <?php $id = $_GET['id']; switch ($id) { case 1: echo "ID 1"; break; case 2: echo "ID 2"; break; default: echo "No ID Selected"; } ?> There is no MySQL here yet, as I'm trying to create a base to build off (I'm testing this by going to index.php?id=1 for example), and that's where it's not displaying properly.When visiting index.php?id=1 & ?id=2, the proper content shows. When I enter something like $id=3, it says No ID Selected, great! But when I go just to index.php, I receive the following error: Notice: Undefined index: id in /home/user/public_html/index.php on line 23 No ID Selected Line 23 is $id = $_GET['id']; Is this a syntax problem, where I've just coded this wrong, or a PHP.ini issue? I'm trying to nail this down before I start inputing the MySQL details and pull from my database. Thank you for the guidance, Jon Aspiring Web Developer @JonEdney1
  7. Hello, I've been a few years remove from working with PHP & MySQL, and even then I would only consider my skill a 2 of 10, but I've decided to get back into it. I'm able to get a query to display on my page for navigation of the page, but when I try to pull data for a new post, nothing posts, but also no error. Here is the code: <?php require('config.php'); ?> <div class="container"> <div class="header"> <img src="images/header.gif" alt="Veterans Of War, A Day of Defeat Squad"> </div> <div class="sidebar_left"> <table class="sidebar_left"> <tr> <td class="sidebar_header">Navigation</td> </tr> <?php // Start Navigation Data $sql = "SELECT * FROM navigation"; $result = mysql_query($sql); $row = mysql_fetch_array($result); if(mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { ?> <tr> <td class="sidebar_row"><a href="<?php echo $row['url']; ?>"><?php echo $row['text']; ?></a></td> </tr> <?php } } else { echo "No data to return"; } // End Navigation Data ?> </table> </div> <div class="content"> <table class="content"> <?php // Start News Data $sql2 = "SELECT * FROM news"; $result2 = mysql_query($sql2); $row2 = mysql_fetch_array($result2); if(mysql_num_rows($result2)) { while ($row2 = mysql_fetch_assoc($result2)) { ?> <tr> <td class="content_header"><?php echo $row2['title']; ?></td> </tr> <td class="content_highlight">Posted by <?php echo $row2['author']; ?> on <?php echo $row2['date']; ?></td> <tr> <td class="content_data"><?php echo $row2['content']; ?></td> </tr> <?php } } else { echo "No data to return"; } // End News Data ?> I changed the second query variables to things like row2 and query2, thinking running row and query was still trying to associate with the navigation pull just above it. I can't even get table row or data information to display, all that outputs is the <table> and </table>, none of the PHP or HTML within. Oddly (at least odd to me), if I change the SELECT FROM to pull from navigation, I can display info from that table. I'm working on learning more, but this I've been looking at for a good hour, and just cannot see why it won't work. Any guidance would be appreciated very much. Jon Linux Support Tech / Aspiring Web Developer
×
×
  • 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.