Jump to content

loops not working how it should


bamfon

Recommended Posts


$sql7 = "SELECT * FROM $datebase1 Where series_name LIKE '$start_letter%' ORDER BY series_name ";
$result7 = mysql_query($sql7) or exit(mysql_error());

$sql2 = "SELECT * FROM $memberreview_table";
$result2 = mysql_query($sql2)or exit(mysql_error());
while ($row = mysql_fetch_assoc($result7) and $row1 = mysql_fetch_assoc($result2) ) {

$series_name = $row['series_name'];





$review_name= $row1['anime_name'];
$member_reviewer  = $row1['reviewer_name'];


if($review_name!=$series_name & $member_reviewer!=$signedin_username ){

$animeid = $row['animeid'];

$pictures = $row['pictures'];
$series_summary  = $row['series_summary'];


?>
<td class="picture" style="width:140px;"><img src="<?php echo $pictures ?>" alt="" width="100" height="100" /></td>
          <td align="left"><a href="./ana_new_review.php<?php echo "?id=".$animeid ?>"><?php echo $series_name ?></a></td>
          <td><a href="./ana_new_review.php<?php echo "?id=".$animeid ?>"><?php echo $series_summary ?> </a></td>
<?php }} ?>

 

What I am trying to do is,  make it list all the info in  datebase1  as long as the name of the review and the reviewer name is not the same

 

 

but using that while function, only show as many rows of info as it is in database2

 

so database 2 only = 3 rows

 

database one only shows 3 rows

 

Sorry I am not really good at explaining stuff

Link to comment
Share on other sites

A while loop will only continue as long as the conditions for the loop are true. With the loop you have above the loop will continue until either one of the mysql_fetch_assoc() calls returns false. So, if one result has 5 records and the other has 5,000 records, the loop will exit after five records are extracted from both because the first one will return false.

 

You say

What I am trying to do is,  make it list all the info in  datebase1  as long as the name of the review and the reviewer name is not the same

 

I really don't see how you are able to make that distinction using two separate, unrelated queries. You likely need to use a JOIN and just do ONE query.But, since I really don't understand your requirements or your table stricture I can't provide any suggestions. Please show the table layout and restate your requirement above and/or give an example.

Link to comment
Share on other sites

What I am trying to do is, make it list all the info in datebase1

 

but if the the review is in databse 2 and the reviewer name is the same as the person logged in it wont show.

 

but using that while function, only show as many rows of info as it is in database2

 

so database 2 only = 3 rows

 

database one only shows 3 rows

 

 

 

 

@ mjdamato

 

would doing it Join table ways bypass

"o, if one result has 5 records and the other has 5,000 records, the loop will exit after five records are extracted from both because the first one will return false."

?

 

Sorry I am not really good at explaining stuff

 

 

Link to comment
Share on other sites

Sorry I am not really good at explaining stuff

 

Then try harder. Don't cop out by making a lame excuse. I asked you to 1) show your table layout and 2) explain your requirements better. You only attempted to provide #2. Yes, a JOIN is what you want to do here. But, I can't provide good advice without knowing your database structure.

 

I will provide a sample query using some wild guesses on your database structure and what I think your requirements are

SELECT *

FROM $datebase1
LEFT JOIN $memberreview_table
  ON $datebase1.reviewID = $memberreview_table.reviewID

WHERE series_name LIKE '$start_letter%'
  AND $memberreview_table.memberName <> $loggedInUserName

ORDER BY series_name

 

Link to comment
Share on other sites

I know how to use join, that why I was asking would it bypass it, So i felt no need to give out my database layout

 

If I am understanding you correctly, what you want can be achieved by using a JOIN with the appropriate conditions. I am by no means an expert, but I consider myself very competent in database queries. To say "I know how to use JOIN" really doesn't indicate one's level of expertise. There are many types of JOINs and virtually a limitless numbers of ways to use them. It is using JOINs in the right way that indicates a persons level of expertise.

 

I asked you to provide an explanation of your database in hopes that I could provide a properly constructed query to get the data you want. Instead you decided to get an attitude and state "I know how to use join". Well, you obviously don't know how to use a while loop, so good luck to you.

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.