Jump to content

craigory83

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

craigory83's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you thank you thank you. Works like a charm.
  2. Okay, so basically my news-like site is supposed to print out article data saved in the database. It does that quite alright, except on the 3rd article (number 2 in SQL rows or columns. whichever it is. I have my counter subtract 1 from the start article to compensate for MySQL) My code: <?php print "<div class = 'menu' align='center'>Newest Stories</div>"; if (isset($_REQUEST['mstart'])) { $start=$_REQUEST['mstart']; } else { $start=1; } if ($start) { $start=1; } $start--; $end=$start+5; $stories = mysql_query("SELECT * FROM stories ORDER BY id DESC LIMIT $start, $end") or die(mysql_error()); $num = mysql_num_rows($stories); $start++; if ($num > 0) { if ($num<$end) { $end = $end-(5-$num); } print "<b><i>Showing stories $start to $end</i></b>"; for ($count=0; $count<$num; $count++) { print "<hr>"; $story = mysql_fetch_array($stories,$count); $id = $story['id']; $headline = $story['headline']; $author = $story['author']; $desc = $story['description']; $content = $story['content']; print "COUNT: $count OF $num ($id)<br>"; print "<a href='index.php?request=story&mstart=$start&story=$id' class='headlinelink'>$headline</a><br>"; print "<div class='author'>Posted by: <a href='index.php?request=author&mstart=$start&author=$author' class='author'>$author</a>.</div>"; print "<div class='desc'>$desc</div><br>"; } } else { print "Error. No stories found. "; } ?> Output: (The COUNT x OF y was to help me figure out what is wrong. In the () by it is the id number of the corresponding MySQL row/column. I even deleted one of the articles to see if it was a specific article error. No luck.)
  3. That is different. So if I remove 1 from the $start variable it should work swimmingly. Thank you very much sir!
  4. I took off 1 from $start and $end and it seems to work now. Do php and mysql have different ideas of it?
  5. Thanks. I'm realllly new to this whole thing, but want to give it a good shot. I've read about the die() function, but never really looked into it enough to impliment it. There is no error, but num is 0 so apparently I am screwing up in my variables.
  6. Hello! First post. I am trying to code out a news website (kinda) I can't seem to fetch the news articles out of SQL. What am I doing wrong? (start is fetched by $_REQUEST. Assume it is 1) $end=$start+5; $stories = mysql_query("SELECT * FROM 'stories' DESC ORDER BY id LIMIT $start, $end"); $num = mysql_num_rows($stories); print $num;
×
×
  • 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.