Jump to content

Recommended Posts

Not sure why this is not working...perhaps I am just too tired.  For some reason the result keeps taking the else path and returning "Nothing" for the $path when I know for a fact there is an entry in the table.

 

Basically I have a table with 5 entries and I want this loop to run 10 times. So during the first loop if it does not find row 1 (a slot field with the number 1 in it) it should come back with "Nothing" in the $path...then on the second loop it should find that row 2 (a slot field with the number 2 in it) does exist and should then place the "win_path" field contents into the $path....and so on

 

$query = "SELECT * FROM $tblname WHERE tbl_hour = $hrcount";
$content = mysql_query($query); 
$num = mysql_num_rows($content);

if ($num != 0) { 
$count = 1;

 $file = fopen("../test/testlist.wsx", "w");
 $wsxpl = "<?wsx version=\"1.0\"?>\r\n";
 $wsxpl .= "<smil repeatCount=\"indefinite\">\r\n";
 while ($count <= 10) {	 
	 while ($row = mysql_fetch_array($content)) {
		$exists[] = $row['slot'];

				if (in_array($count, $exists)) {

				 $path = $row["win_path"];																	

				 } else {

					$path = "Nothing";																	

				}
		}
		$wsxpl .="\t<media src=\"" . $path . "\"/>\r\n";
		$count++;
	 }
	 $wsxpl .="</smil>";																
	 fwrite($file, $wsxpl);
	 fclose($file);
	}

Link to comment
https://forums.phpfreaks.com/topic/127905-solved-more-crazy-loops-in-the-nest/
Share on other sites

 $wsxpl = "<?wsx version=\"1.0\"?>\r\n";
 $wsxpl .= "<smil repeatCount=\"indefinite\">\r\n";
 while ($count <= 120) {	 
                 mysql_data_seek($content,0);// <-- insert this line
	 while ($row = mysql_fetch_array($content)) {
		$exists[] = $row['slot'];

Guys, I am sooo stuck on this...nothing I try seems to work...here is what I have code-wise. I stripped all the excess stuff out to simplify it.

 

Loops 10 times. Current table has five rows. each loop should display the result of an existing row or display the word "nothing".  The content of the existing 5 rows are different but all this returns is the content from the 5th row or nothing.

 

$tblname = "test1";

$query = "SELECT * FROM $tblname WHERE tbl_hour = 1";
$content = mysql_query($query); 
$num = mysql_num_rows($content);

if ($num != 0) { 
$count = 1;

 while ($count <= 10) {
 	mysql_data_seek($content,0);	 
	 while ($row = mysql_fetch_array($content)) {

		$exists[] = $row[tbl_slot];

				if (in_array($count, $exists)) {

				 $path = $row["win_path"];																	

				 } else {

				 $path = "Nothing";																	

				}
		}
		echo $count . ": " . $path;
		echo "<br />";
		$count++;
	 }
}																							

unfortunately through some absurd circumstances I do not have the ability to dump the DB.  Below is the code used to create the test DB I am allowed to run.

 

$sql = "CREATE TABLE $tblname
(
entry_id INT( NOT NULL AUTO_INCREMENT, 
win_path VARCHAR(50) NOT NULL,
tbl_hour INT(3) NOT NULL,
tbl_slot INT(3) NOT NULL,
PRIMARY KEY (content_id)
)";

 

Creates a pretty simple table. Each entry is common under "tbl_hour" which is equal to "1".

 

"tbl_slot" is a unique numeric value between 1 and 10. This is used to designate the order the entries are to be played and writes them to the xml file.

 

So to test this I put in only 5 even numbers in the DB with a unique value of 2, 4, 6, 8, 10, in the "tbl_slot" field...and in the "win_path" that has the different media that is to be written to the playlist in the order determined by "tbl_slot".

 

The output I would expect is like this:

 

1: Nothing

2: image1

3: Nothing

4: image2

5: Nothing

6: image3

7: Nothing

8: image4

9: Nothing

10: image5

 

However with what I have now I am getting this:

 

1: Nothing

2: image5

3: Nothing

4: image5

5: Nothing

6: image5

7: Nothing

8: image5

9: Nothing

10: image5

 

I know the problem I just don't know or understand how to fix it.  The query only finds five rows and I am asking it to basically fill in values for 10 rows then check each row to see if it exists and if it does then do something...if it doesn't do something else. 

This version gives the output you are looking at:

<?php
$query = "SELECT * FROM $tblname WHERE tbl_hour = 1";
$content = mysql_query($query); 
$num = mysql_num_rows($content);

 while ($row = mysql_fetch_assoc($content))
	$exists[$row['tbl_slot']] = $row['win_path'];
for ($count=1;$count<=10;$count++) {
	$path = (key_exists($count,$exists))?$exists[$count]:'Nothing';
	echo $count . ': ' . $path . '<br>';
} 
?>

 

Ken

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.