Jump to content

[SOLVED] mysql while loop thing?


Zeradin

Recommended Posts

I don't really know what to call this but for some reason i can read out of mysql and then when i try to do it again it doesn't work

 

				  <strong class="red">Reviews</strong><br />';
			       while(list($id, $title)  = mysql_fetch_row($result2)) {
					echo '<a href="reviews.php?rtyp=music&id='.$id.'">'.$title.'</a><br />';
					}
		echo '<br />
			  <br />
			  <strong class="red">Articles</strong><br />';
			       while(list($id, $title)  = mysql_fetch_row($result2)) {
					echo '<a href="reviews.php?rtyp=music&id='.$id.'">'.$title.'</a><br />';
					}
		echo '<br /><br />

 

I wasn't originally trying to do the same thing twice, I was doing a $result3 thing from these:

 

//get reviews
$query2 = 'SELECT * FROM reviews WHERE reviewer = "'.$info['username'].'"';
$result2 = mysql_query($query2) or die ("error in query: $query2. ".mysql_error());
$revinfo = mysql_fetch_array($result2) or NULL;

//get articles
$query3 = 'SELECT * FROM articles WHERE writer = "'.$info['username'].'"';
$result3 = mysql_query($query3) or die ("error in query: $query3. ".mysql_error());
$wrtinfo = mysql_fetch_array($result3) or "error in query: $query3. ".mysql_error();

 

I know it's probably an obvious thing but i've been looking at it forever and can't see my mistake.

 

Link to comment
Share on other sites

You can only run the query once,

why not change it like this

			  <strong class="red">Reviews</strong><br />';
			       while(list($id, $title)  = mysql_fetch_row($result2)) {
					echo '<a href="reviews.php?rtyp=music&id='.$id.'">'.$title.'</a><br />';

		echo '<br />
			  <br />
			  <strong class="red">Articles</strong><br />';
					echo '<a href="reviews.php?rtyp=music&id='.$id.'">'.$title.'</a><br />';
					}
		echo '<br /><br />

Link to comment
Share on other sites

but changing it to how i had it , would be more logical. :)

 

but i really wanted to do this

			  <strong class="red">Reviews</strong><br />';
			       while(list($id, $title)  = mysql_fetch_row($result2)) {
					echo '<a href="reviews.php?rtyp=music&id='.$id.'">'.$title.'</a><br />';
					}
		echo '<br />
			  <br />
			  <strong class="red">Articles</strong><br />';
			       while(list($id, $title)  = mysql_fetch_row($result3)) {
					echo '<a href="articles.php?id='.$id.'">'.$title.'</a><br />';
					}
		echo '<br /><br />

 

do i still have to rewind it?

 

edit2: wait that won't do anything

Link to comment
Share on other sites

hey, when i do the seek and result3 is null i get this error

 

Warning: mysql_data_seek() [function.mysql-data-seek]: Offset 0 is invalid for MySQL result index 6 (or the query data is unbuffered)

 

tried putting it in if loops, but didn't fix it:

				  if ($result2 != NULL){
			       while(list($id, $title)  = mysql_fetch_row($result2)) {
					echo '<a href="reviews.php?rtyp=music&id='.$id.'">'.$title.'</a><br />';
					}
					}
			else {
				echo '<br /><br /><br />';
				 }
		if ($result3 != NULL){
				mysql_data_seek ($result3, 0) or NULL;  // rewind to row 0
		echo '<br />
			  <br />
			  <strong class="red">Articles</strong><br />';
			       while(list($id, $title)  = mysql_fetch_row($result3)) {
					echo '<a href="articles.php?rtyp=music&id='.$id.'">'.$title.'</a><br />';
					}
		}
		else {
			echo '<br /><br /><br />';

 

any ideas?

Link to comment
Share on other sites


$num2 = mysql_numrows($result2);

			  if ($num2 != 0){
			       while(list($id, $title)  = mysql_fetch_row($result2)) {
					echo '<a href="reviews.php?rtyp=music&id='.$id.'">'.$title.'</a><br />';
					}
					}
			else {
				echo '<br /><br /><br />';
				 }
$num3 = mysql_numrows($result3);

		if ($num3 != 0){
				mysql_data_seek ($result3, 0) or NULL;  // rewind to row 0
		echo '<br />
			  <br />
			  <strong class="red">Articles</strong><br />';
			       while(list($id, $title)  = mysql_fetch_row($result3)) {
					echo '<a href="articles.php?rtyp=music&id='.$id.'">'.$title.'</a><br />';
					}
		}
		else {
			echo '<br /><br /><br />';

 

??????

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.