PHP - Inner While Loop Not Working.. It Limit To Only One Row
This is a code pinch from a webpage of my project. Here I want to display user selected categories and then want to display its subjects that belong to category. There, users could have more than 1 category and It no problem I can print all those category in my first while loop... but problem is when Im try to print subjects it has only one row as a result.. there are more subjects in each category. can anybody tell me what has happens?
this is my code.... Note: both queries are working properly.. I tried those user mysql client program. Code: [Select] <?php require_once ('../../includes/config.inc.php'); require_once( MYSQL1 ); $q = "SELECT institute_category.category_id, category_name FROM institute_category INNER JOIN category ON institute_category.category_id = category.category_id WHERE institute_category.institute_id = $instituteId"; $r = mysqli_query( $dbc, $q); while ( $row = mysqli_fetch_array ( $r, MYSQLI_ASSOC) ) { $categoryId = $row['category_id']; $category = $row['category_name']; echo '<fieldset class="alt"> <legend><span>Category : <em style="color: red;">' . $category . '</em></span></legend>'; $qy = "SELECT category_subject.category_id, category_subject.subject_id, subjects FROM category_subject INNER JOIN category ON category_subject.category_id = category.category_id INNER JOIN subject ON category_subject.subject_id = subject.subject_id WHERE category_subject.category_id = $categoryId"; $result = mysqli_query( $dbc, $qy); $c = $i = 0; echo '<table class="form_table" ><tr>'; while($row = mysqli_fetch_array( $result, MYSQLI_ASSOC )){ // if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row: if( ($c % 2) == 0 && $c != 0){ echo "</tr><tr>"; } echo '<td width="50%"><input type="checkbox" name="subject[]" value="' . $row['category_id'] . ":" . $category . ":" . $row['subject_id'] . ":". $row['subjects'] . '" /> ' . $row['subjects'] . '</td>' . "\n"; $c++; } // while.. // in case you need to fill a last empty cell: if ( ( $i % 2 ) != 0 ){ // str_repeat() will be handy when you want more than 2 columns echo str_repeat( "<td> </td>", ( 2 - ( $i % 2 ) ) ); } echo "</tr></table>"; } echo '</fieldset>'; ?> any comments are greatly appreciated.. thank you Similar Tutorials
I want to run this loop until it has created 50 or a 100 links, max. At present it continues running even though no inputs are being added to the database. I suspect, it keeps looping through and collecting duplicates and then not adding them to the database. I see this as two options, I either limit the number of loops or must find someway for the pages that have already been crawled to be skipped. I am busy doing a php course and the lecturer is not answering questions about how the code could be improved. I figure that if you are going to do something in a training course it should be able to do what it needs to and if it doesn't it needs a little alteration. function followLinks($url) { global $alreadyCrawled; global $crawling; global $hosta; $parser = new DomDocumentParser($url); $linkList = $parser->getLinks(); foreach($linkList as $link) { $href = $link->getAttribute("href"); if((substr($href, 0, 3) !== "../") AND (strpos($href, "imagimedia") === false)) { continue; } else if(strpos($href, "#") !== false) { continue; } else if(substr($href, 0, 11) == "javascript:") { continue; } $href = createLink($href, $url); if(!in_array($href, $alreadyCrawled)) { $alreadyCrawled[] = $href; $crawling[] = $href; getDetails($href); } } array_shift($crawling); foreach($crawling as $site) { followLinks($site); } Edited January 29 by guymclarenza added info I have a while loop in a script that is running for a very long time due to the large values that are passing through it. Below is the link to the pastebin code and code embedded in this forum. Loop Statement Snipet if (!$user_class->invincible) { if (!$defender->invincible) { while ($yourhp > 0 && $theirhp > 0) { $damage = round($defender->moddedstrength) - $user_class->moddeddefense; $damage = ($damage < 1) ? 1 : $damage; if (!$wait) { $yourhp = $yourhp - $damage; ++$number; $log[] = $number . ": " . $defender->formattedname . " hit you for " . prettynum($damage) . " damage using their " . $defender->weaponname . ". <br />"; } else $wait = 0; if ($yourhp > 0) { $damage = round($user_class->moddedstrength) - $defender->moddeddefense; $damage = ($damage < 1) ? 1 : $damage; $theirhp = $theirhp - $damage; ++$number; $log[] = $number . ": " . "You hit " . $defender->formattedname . " for " . prettynum($damage) . " damage using your " . $user_class->weaponname . ". <br />"; } } $log = array_slice($log, -10, 10, true); foreach($log as $text) echo $text; } else $yourhp = 0; } else $theirhp = 0;
My issue is that $yourhp and $theirhp can be in the 100's of thousands causing this to loop half a million plus times. I was curious if there was a way to only show the first few lines and last few lines of this but still retain the increment value that's created? Thanks so much in advance. NICON I am working to echo the results in a while or for loop... Both of my sample codes work, but the results are wrong! The while loop ONLY echos a result IF the first record in the postings table matches the id passed (does not display a result unless the first record has a match) The if loop displays ALL listings with the same name (counts them all) so there are no unique listings! <?php $posts_by_city_sql = "SELECT * FROM postings WHERE id='$_GET[id]'"; $posts_by_city_results = (mysqli_query($cxn, $posts_by_city_sql)) or die("Was not able to grab the Postings!"); /* While Loop */ while($posts_by_city_row = mysqli_fetch_array($posts_by_city_results)) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } /* For Loop */ $posts_by_city_row = mysqli_fetch_array($posts_by_city_results); for ($i=0; $i<sizeof($posts_by_city_row); $i++) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } ?> Results with for loop (there are 7 total unique book names, but it's just counting the first match on id 7 times like below): AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners Unless buffer overflows or breaking out of code to perform a new command are problems that have been solved.... I am trying to figure out the proper PHP method for setting a boundary on a variable within a script. I have this variable $name which is fed a value from $_POST['name'] from a form field. Now this form field is limited in the HTML to accept only 20 characters, but someone could easily edit the form or outgoing post data. So I want to know how to limit the variable size in the script. In other languages it could be something like this: var name(20). So how do I do that in PHP? I'm trying to turn this while loop into a for loop and am unable to get my result set to display properly in the for loop. The while works fine I just want to be able to have more control over which information is shown in my table as I loop and was wanting to use a for loop that way I can take advantage of the counter variable while i"m displaying my information. Any help would be appreciated. while ($row = mysql_fetch_assoc($data_result_set)) { echo "<td>".$row["product_id"]."</td>"; echo "<td>".$row["city"]."</td>"; echo "<td>".$row["quantity"]."</td>"; } *** I'm wanting it to look like something like this but can't figure out how to properly work in which row to display with the $i variable. $count=mysql_num_rows($data_result_set); for($i = 0; $i <= $count; $i++){ echo "<td>".mysql_fetch_assoc[$i]["product_id"]."</td>"; echo "<td>".mysql_fetch_assoc[$i]["city"]."</td>"; echo "<td>".mysql_fetch_assoc[$i]["quantity"]."</td>"; } I know the syntax for the for loop is totally off with the method mysql_fetch_assoc just dropped in there like a jerk but I'm just kinda pseudoing it out. Any help would be appreciated. Thanks in advance. It's only displaying the first result and not the others. What am I doing wrong? I'm selecting the items the user occupies. Then I'm selecting the name and image of that item from the item table. Code: [Select] echo "<table cellspacing=\"0\" class=\"news\" align=\"center\">"; echo "<tr>"; $sql = "SELECT * FROM useritems WHERE userid='".$_SESSION['userid']."' LIMIT $offset, $rowsperpage"; //selects all the users items to whoever is logged in $result = mysqli_query($cxn,$sql) or die(mysqli_erro($cxn)); $imagecount = 0; while ($row = mysqli_fetch_assoc($result)) //while there are still results { extract($row); $quantity = $row['quantity']; $itemid = $row['itemid']; $sql = "SELECT * FROM items WHERE itemid='".$itemid."'"; //selecting the name and image of the item that is displaying $result = mysqli_query($cxn, $sql) or die(mysqli_error($cxn)); $row = mysqli_fetch_assoc($result); $name = $row['name']; $image = $row['image']; if ($imagecount%5 == 0) //after 5 items have been listed, start a new line { echo "</tr>"; echo "<tr>"; } } echo "<td width=\"120px\" align=\"center\">"; echo "<img src=\"http://www.elvonica.com/".$image."\"><br>"; echo $name." (".$quantity.")"; echo "</td>"; $imagecount++; //after one item has been displayed, redo the loop if there are still results } echo "</table>"; Hello everyone! I am trying to pull from mysql a row of first names in a while loop but I keep getting the error message Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in line 52 The code is; <?php $first_name = $_POST['firstname']; $last_name = $_POST['lastname']; $full_name = $_POST['firstname'] . ' ' . $_POST['lastname']; require_once ('swdb_connect.php'); $query = "INSERT INTO description(firstname, lastname) VALUES ('$first_name', '$last_name')"; $result = @mysql_query ($query); while($row = mysqli_fetch_array($result)) { echo $row['firstame'] . '<br />'; ?> I don't understand why I get the error message, I have over 20 names in mysql If anyone can help that would be great Okay I am trying to do a for loop within a while loop and its so far not working. Here is what I currently have. It echo's nothing out. Also If I remove the Code that generates information from the for loop It echo's out perfectly so It has something to do with the for loop. PHP Code so Far: Code: [Select] <?php if(isset($_POST['system'])){ $system = $_GET['system']; }else{ $system = 1; } $q = "SELECT * FROM `planets` WHERE `system` = '$system' ORDER BY `id` ASC LIMIT 9"; $res = mysql_query($q) or die("Error:<br />".mysql_error()); $couny = mysql_num_rows($res); while($row = mysql_fetch_array($res)){ for($i=1; $i>=$couny; $i++){ ?> <li> <span <?php if($i=1){echo "id='mercury'";} if($i=2){echo "id='venus'";} else if($i=3){echo "id='earth'";} else if($i=4){echo "id='mars'";} else if($i=5){echo "id='jupiter'";} else if($i=6){echo "id='saturn'";} else if($i=7){echo "id='uranus'";} else if($i=8){echo "id='neptune'";} else if($i=9){echo "id='pluto'";}?>id="mercury"><?php echo $row['name']; ?></span> <p><?php if($colony['building11'] >= $row['building11']){?> This Colony Currently Has the Following:<br /> Hydrogen: <?php echo num($row['recource1']); ?><br /> Gold: <?php echo num($row['recource1']); ?><br /> Platinum: <?php echo num($row['recource1']); ?><br /> Silver: <?php echo num($row['recource1']); ?><br /> Bio-Waiste: <?php echo num($row['recource1']); ?><br /> Plasma: <?php echo num($row['recource1']); ?><br /> Metal: <?php echo num($row['recource1']); ?><br /> <?php }else{?> <font color="red">Insufficiant Observatory Level!</font><br /> Hydrogen: ???????????????<br /> Gold: ???????????????<br /> Platinum: ???????????????<br /> Silver: ???????????????<br /> Bio-Waiste: ???????????????<br /> Plasma: ???????????????<br /> Metal: ???????????????<br /> <?php } ?></p> </li> <?php } } ?> Thanks Brian. PS. The Attached Image is what it looks on my end the for and while loops displays the planets in the system right under the red Solar System Star Text. Thank you again for any help. Can anyone help me with why this code would only send 1 email when the query returns 8 rows?
I am pretty sure it will be simple but I can't find the problem!
$sql = "SELECT email, supplier_id FROM tbl_suppliers"; $stmt = $db->prepare($sql); $stmt->execute(); foreach($db->query($sql) as $row){ $supp_id = $row['supplier_id']; $emailCSV->setEmailMessage("some generic text message"); $email = $row['email']; $emailCSV->sendEmail("me@me.com",$email,"Quote Request"); } I have a while loop nested inside of another while loop to populate a drop-down select box for each result from the parent while loop. The inner loop only gets run once though... any ideas on how to fix this without it being extremely data heavy? Hello all, I am having trouble with a piece of code. I have used the same piece of code on a different server and I had no problems. Suddenly I do. - I use this code to load info into a Flash website to browse through all rows in a table; - Inside the table currently there is one record; - NumLow is being passed through the url; - echo "&aantalEvenementen=".$aantalEvenementen; shows 1 record just fine; - the record doesn't get printed though... the error is somewhere in the while loop. Hope someone can point me in the right direction! Cheers, Code: [Select] // Connect to mySQL Server $DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error bij het verbinden met de MYSQL server: " . mysql_error()); // Select mySQL Database mysql_select_db($DBName, $DBConn) or die("Error bij het verbinden met de MYSQL database: " . mysql_error()); //amount of rows that are shown at once $numComments = 1; //select the right table $sql = "SELECT * FROM $table"; //loading events $nieuweEvenementen = mysql_query($sql, $DBConn) or die("Error bij het ophalen van de concerten: " . mysql_error()); //amount of rows $aantalEvenementen = mysql_num_rows($nieuweEvenementen); //order rows $sql .= ' ORDER BY `concertDatum` DESC LIMIT ' . $_GET['NumLow'] . ', ' . $numComments; //loaded row $geladenEvenement = mysql_query($sql, $DBConn) or die("Error bij het laden van het concert: " . mysql_error()); //echo amount of rows echo "&aantalEvenementen=".$aantalEvenementen; //if no records, display message, otherwise print row if($aantalEvenementen == 0) { echo "&concertOmschrijving=Er zijn geen concerten. U kunt nieuwe concerten aanmaken via de concertenkalender."; } else { while ($array = mysql_fetch_array($geladenEvenement)) { $concertNaam = mysql_result($geladenEvenement, $i, 'concertNaam'); $concertArtiest = mysql_result($geladenEvenement, $i, 'concertArtiest'); $concertDatum = mysql_result($geladenEvenement, $i, 'concertDatum'); $concertTijd = mysql_result($geladenEvenement, $i, 'concertTijd'); $concertOpen = mysql_result($geladenEvenement, $i, 'concertOpen'); $concertOmschrijving = mysql_result($geladenEvenement, $i, 'concertOmschrijving'); echo "&concertNaam=".$concertNaam; echo "&concertArtiest=".$concertArtiest; echo "&concertDatum=".$concertDatum; echo "&concertTijd=".$concertTijd; echo "&concertOpen=".$concertOpen; echo "&concertOmschrijving=".$concertOmschrijving; $i++; } } // if there are no more records (all are loaded), show message if($_GET['NumLow'] > $aantalEvenementen) { echo "$eventOmschrijving=Alle concerten zijn reeds geladen."; } } I have never used cURL before but I need to use it for developing a facebook application. What I am trying to do is create a status update scheduler. There are two tables in my database. One table has generic updates for each day of the week an the other had special events. My script checks the day, checks to see if there is a special event in the future on that day, and if there is reminds guests of the upcoming event. If there is no event it posts the generic status. Code: [Select] <?php include('config.php'); $result2 = mysql_query("select facebook_id,facebook_access_token from admin where username='users'"); $row = mysql_fetch_array($result2); $facebook_id = $row['facebook_id']; $facebook_access_token = $row['facebook_access_token']; $day = date('N'); $result2 = mysql_query("select * from events where date > CURDATE() order by date ASC") or die(mysql_error()); $num_rows = mysql_num_rows($result2); if($num_rows == 0) { $result2 = mysql_query("select * FROM alerts WHERE id='$day'") or die(mysql_error()); $row1 = mysql_fetch_array($result2); echo 'There are no events just alerts'; } else { while($row = mysql_fetch_array($result2)){ if(date('N',strtotime($row[date])) == $day) { $id = $row['id']; $result1 = mysql_query("SELECT * FROM events WHERE id = $id") or die(mysql_error()); $row1 = mysql_fetch_array($result1); } else { $result1 = mysql_query("SELECT * FROM alerts WHERE id = $day") or die(mysql_error()); $row1 = mysql_fetch_array($result1); } } } $params = array('access_token' => $facebook_access_token, 'message' => $row1[alert_message], 'name'=> $row1[alert_name], 'caption' => $row1[alert_caption], 'link' => $row1[alert_link], 'description' => $row1[alert_description], 'picture' => $row1[alert_picture] ); $url = "https://graph.facebook.com/$facebook_id/feed"; $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_URL => $url, CURLOPT_POSTFIELDS => $params, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_VERBOSE => true )); $result = curl_exec($ch); ?> The problem seems to be occurring when the While loop is accessed. I have used 'echo' to follow the variables through the script and it all seems to be working. However if I try and execute the cURL and the While Loop has run then it does not seem to work. I know the cURL part works becuase if the variables cause the first IF statement default to ELSE then it runs fine. Any help would be GREATLY appreciated. I am a noob at php, looking to become great. My php loop only seems to draw 1 row from the database when listing it out. Here is the loop <?php require('header.php'); mysql_select_db('center'); $sql = "select username, password from users"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $user = $row['username']; $pass = $row['password']; echo "<table border='1'>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>$user</td>"; echo "<td>$pass</td>"; echo "</tr>"; } echo "</table>"; ?> I'm trying to create a part of a script where by the system will generate a sku code and loop through out to see if this exists in the database, if the sku does the script adds one too the code so 001 will turn to 002 then it will keep looping until it finds a SKU that isn't in the database.
However I can get the script to keep generating the new SKU codes but it will only test the first SKU code so the loop will keep going if it exists.
$number=001; if(isset($_POST['submit'])){ $product = $_POST['product']; $brand = $_POST['brand']; $description = $_POST['description']; $contruct=strtoupper($product."-".$brand."-".$description); $number=sprintf("%03s",$number); $check_for=$contruct."-".$number; $query=$cc_db->query("SELECT `sku` FROM `product` WHERE `sku`='".$check_for."'"); $fetch=$cc_db->fetch_object($query); $checking=$cc_db->num_rows($query); while($checking > 0){ echo"$check_for is there : $checking rows : $fetch->sku<br>"; $number=$number+1; $number=sprintf("%03s",$number); $check_for=$contruct."-".$number; } echo $checking; echo $check_for; } I have the following form the just has one field. Code: [Select] <html> <head> <title>Post</title> </head> <body> <form action="worldpay_callback.php" method="post"> <input type="text" name="username" id="username" /> <input type="submit" name="submit" id="submit" value="send" /> </form> </body> </html> I am then posting the form to the following page that is meant to loop through all of the post values and save them to a text file. For some reason my foreach loop doesn't seem to be working as done of the post values are getting written to the text file. Can anyone see anything I'm doing wrong? Code: [Select] $myFile ="notifications.txt"; $fh = fopen($myFile, 'w+') or die("can't open file"); foreach($_POST as $k=>$v) { $data = 'POST: Key:'.$k.' - Value:'.$v ." \n"; fwrite($fh, $data); } fclose($fh); return "[OK]"; Thanks for any help hello.. In this script. if part is working properly. but elseif part not working i expect. it display only 1 category and its subjects. Anybody can tell me what the mistake that I have did... Here is my script Code: [Select] } elseif ( isset($_POST['category']) && ( sizeof( $_POST['category']) == 2 || sizeof( $_POST['category']) == 3 )) { $q = 'SELECT * FROM category ORDER BY category_id'; $r = mysqli_query( $dbc, $q); while($row = mysqli_fetch_array( $r, MYSQLI_ASSOC )) { foreach( $category as $value ) { if ( $value == $row['category_id']) { echo '<input type="radio" name="category[]" value="' . $row['category_id'] . '" class="radio" />'; echo '<label for="" class="radio"> ' . $row['category_name'] . ' <strong>: Mark this category as my "Main Category"</strong></label><br />'; $q = "SELECT category_subject.category_id, category_subject.subject_id, subjects FROM category_subject INNER JOIN category ON category_subject.category_id = category.category_id INNER JOIN subject ON category_subject.subject_id = subject.subject_id WHERE category_subject.category_id = {$row['category_id']}"; $r = mysqli_query( $dbc, $q); $c = $i = 0; echo '<table class="form_table" ><tr>'; while($info = mysqli_fetch_array( $r, MYSQLI_ASSOC )){ // if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row: if( ($c % 2) == 0 && $c != 0){ echo "</tr><tr>"; } echo '<td width="50%"><input type="checkbox" name="category[]" value="' . $info['subject_id'] . '" /> ' . $info['subjects'] . '</td>'; $c++; } // while.. // in case you need to fill a last empty cell: if ( ( $i % 2 ) != 0 ){ // str_repeat() will be handy when you want more than 2 columns echo str_repeat( "<td> </td>", ( 2 - ( $i % 2 ) ) ); } echo "</tr></table>"; } } } } I am trying to delete records across 3 tables but my code does not work. Code: [Select] $query = ("SELECT `propertyref` FROM `feed_property` WHERE `status` = 'Sold' ")or die(mysql_error()); $result = mysql_query($query); if (isset($result)) { while ($row = mysql_fetch_array($result)): $ref1 = mysql_real_escape_string($row['propertyref']); $query1 = ("DELETE FROM `feed_property`, `feed_images`, `feed_characteristics`\n" . "USING `feed_property` INNER JOIN `feed_images` INNER JOIN `feed_characteristics`\n" . "WHERE feed_property.propertyref = '$ref1'\n" . " AND feed_images.propertyref = feed_property.propertyref\n" . " AND feed_characteristics.propertyref = feed_property.propertyref; ")or die(mysql_error()); echo $query1; endwhile; if(!mysql_query($query1)){ echo '<h1 style="color: red;">Error</h1><p>', mysql_error(), '</p>'; } else { echo '<h1 style="color: red;">Properties have been removed from the database</h1>'; } } Query1 echos as: Code: [Select] DELETE FROM `feed_property`, `feed_images`, `feed_characteristics` USING `feed_property` INNER JOIN `feed_images` INNER JOIN `feed_characteristics` WHERE feed_property.propertyref = 'abc1' AND feed_images.propertyref = feed_property.propertyref AND feed_characteristics.propertyref = feed_property.propertyref; DELETE FROM `feed_property`, `feed_images`, `feed_characteristics` USING `feed_property` INNER JOIN `feed_images` INNER JOIN `feed_characteristics` WHERE feed_property.propertyref = 'abc2' AND feed_images.propertyref = feed_property.propertyref AND feed_characteristics.propertyref = feed_property.propertyref; The query completes without errors but does not delete the entries in the DB. If I run the query singly in PHP My Admin it functions correctly. thanks for your help Hi guys Probably a simple but trying to figure out why I cant get this while loop to work (at least I think its the loop) Query works as it returns 1 row, but not all of them. Any help would be great! $sql = "SELECT * FROM requests ORDER BY leave_after DESC"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { echo '<div id="resultholder">'; echo "<p>Request ID:" . $row['id'] . ", User ID: " . $row['user_id'] . ", Departing From: " . $row['departing'] . ", Going To: " . $row['destination'] . " , Leaving After: " . $row['leave_after'] . " , but Arriving Befo " . $row['arrive_before'] ."</p></div>"; echo '</div>'; } } } Thanks! Hi brains... I must be missing some core concept here that I hope someone can set me straight on.. I have a database query that returns say 8 rows. Here's how I know... $link6_result10 = mysql_query($link6_sql10) or die("Link6 SQL10 Failed: Function drawInventory: " . mysql_error()); $link6_rows10 = mysql_num_rows($link6_result10); $link6_array10 = mysql_fetch_array($link6_result10, MYSQLI_ASSOC); echo "You have $link6_rows10 items in your inventory."; <<---- returns 8 So why in the world does this not work??? What is the flaw in my logic? $srchStr = null; foreach ($link6_array10 as $sn) { $srchStr .= " SerialNumber = '$sn' OR"; echo "SN is $sn "; } The only echo output of the foreach function is "SN is 12345" Not the 8 rows of content that I would expect. isn't this how foreach loops should work? Why do I not see "SN is 12345 SN is 23456 SN is 34567 etc..."????? I'm confused. Thanks guys for any help. Hello guys i used the eval function but it does not echo anything back in the while loop ..the $new_string function contains "preg_split("/\.\(.*\)\.\(.*\)/", $file);", same as $parts..i need some guidance, thanks! <?php //"$DOCUMENT_ROOT"."new/"; $current_dir = 'C:\xampp\htdocs\Audit_Reports'; //Put in second part, the directory - without a leading slash but with a trailing slash! $dir = opendir($current_dir); // Open the sucker $newArgument = $_POST[argument]; $newArgument1 = $_POST[argument1]; $string ='preg_split("/\.\(.*\)\.\(.*\)/", $file);'; $new_string = preg_replace("#\/\\\.\\\\\(\.\*\\\\\)#","/\.\\($newArgument\)",$string); $new_string = preg_replace("#\\\.\\\\\(\.\*\\\\\)#","\.\\($newArgument1\)", $new_string); echo ("<p><h1>List of Audit Reports:</h1></p><hr><br />"); while ($file = readdir($dir)) // while loop { $parts = preg_split("/\.\(CLIENT\)\.\(.*\)/", $file); // $part = eval($new_string); if (is_array($parts) && count($parts) > 1) { // does the dissected array have more than one part $extension = reset($parts); // set to we can see last file extension if ($extension == "Audit_Report" OR $extension == "audit_report") // is extension ext or EXT ? echo "<a href=\"$file\" target=\"_blank\"> $file </a><br />"; // If so, echo it out else do nothing cos it's not what we want } } echo "<hr><br />"; closedir($dir); // Close the directory after we are done ?> The below codes are done in a while loop Result:ArrayArrayArrayArrayArrayArrayArrayArrayArrayArra yArrayArray $parts = preg_split("/\.\(A\)\.\(A\)/", $file); echo $parts; Result:No Output $part = eval($new_string); echo $part; |