PHP - Continuous Looping Through Dynamic Links
Can someone please help me?
Scenario: Database table with varying amount of records, these will be displayed on a big screen with no user interaction, updating every set amount of time say 15 seconds. Once new data enters the database the page updates and shows that record. As there is only limited space on the screen i can only show e.g 1 record per page. I setup pagination which splits these records up into separate pages. so if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * 1; $query = "SELECT * FROM table ORDER BY id ASC LIMIT $start_from, 1"; // run the query and store the results in the $result variable. $result = $mysqli->query($query) or die(mysqli_error($mysqli)); then output the links $total_pages = ceil($total / 1); for ($i=1; $i<=$total_pages; $i++) { echo "<a href=bigscreen.php?page=".$i.">".$i."</a> "; } This is all working fine and splits the pages and displays the links. Problem: I have been trying to get the page bigscreen.php to automatically loop through the pages that are created e.g 3 records = 3 pages so i want it to load bigscreen.php?page=1 then wait for 15 seconds then update to bigscreen.php?page=2 then 15 seconds then update to bigscreen.php?page=3 then back to bigscreen.php?page=1 and this will continue to do this for the amount of pages created. I have tried various methods but i am struggling. I keep getting a redirect loop error in chrome when i setup my loop. I was thinking of putting the links into an array? but i dont know that will work! Any help or tips would be greatly appreciated! Similar TutorialsThis is a question about dynamic links. At the moment I have a dynamic page from a table, I'll call it tableA. The links all work fine, so when clicked, information is displayed from the table. The issue will be when I come to create a new table entry. This new pages (or entry), will itself contain a link to other information. Assuming I have the required information in tableA, how do I activate a dynamic link from within a page that itself dynamically produced? I use PDO for the link to the database, and the page that shows the text uses a form, with buttons to allow the user to select a menu item. The php: <?php // Connect to the databaase $PDO = new PDO("mysql:host=****;dbname=****", "****", "****"); // set the PDO error mode to exception $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Set up defaults $current_title = ""; $current_page_data = ""; // Check if the user posted the page if($_SERVER['REQUEST_METHOD'] == 'POST') { // Check if user pressed a menu button if(isset($_POST["menu"])) { // User has selected a menu, meaning a page was selected, now load the page $current_title = filter_input(INPUT_POST, "menu"); // Now get current data from the database, if the page was never created, add it to the database $stmt = $PDO->prepare("SELECT * FROM pages WHERE pageheader=?"); $stmt->execute([$current_title]); $row = $stmt->fetch(); if($row) { // Page is in the databaswe already, load the text for it if(isset($row["pagetext"]) AND trim($row["pagetext"])!="") { $current_page_data = $row["pagetext"]; } } else { // Page was never created, add it with blank text $current_page_data = "This page is under contruction!<br><br>Please check back again later!"; } } } ?> The form (partial): <form name="****form" method="post" action="#"> <table id="timeline"> <tr> <td id="contentMenu"> <span class="item"> <div class="dropdown"> <button class="dropdownButton">Pre 3150 BC</button> <div class="dropdownContent"> <button name="menu" type="submit" value="Predynastic Egypt">Predynastic Egypt</button> <button name="menu" name="menu" value="Lower Egypt">Lower Egypt</button> <button name="menu" type="submit" value="Upper Egypt">Upper Egypt</button> <button name="menu" type="submit" value="Upper and Lower Egypt">Upper & Lower Egypt</button> </div> </span> .... </td> </tr> </table> </form> <!-- page content --> <hr> <h1 class="center"><?php echo $current_title; ?></h1> <hr> <?php echo $current_page_data; ?>
Hey, thank you for taking time to read this and for possibly helping me sort this. So I'm trying to make it so: Code: [Select] http://mysite.com/thing/key is rewritten as: http://mysite.com/thing.php?k=key while keeping a general rule for: http://mysite.com/thing being written to: http://mysite.com/thing.php Please help thank you. The table in the script has a set max-width. How can now a too long continuous text string as in "blaaaaaaaa", which also does not contain a space or dash, be broken, so the table does not become stretched to far? Which function is used for this? i am working on this search engine. and in the advanced section you can turn on/off some of the options. So it you turn on an option it will search another table and so on. Instead of building a massive query and left joining lots of stuff. I tried a different approach. There is always a basic query and it returns the results to an array like this Code: [Select] $sql = mysql_query("SELECT SQL_CACHE id FROM table WHERE field LIKE '$getquery' ORDER BY field"); while ($row = mysql_fetch_array($sql)) { $idArray[] = $row['id']; } mysql_free_result($sql); and if something is turned on then it adds something like this: Code: [Select] if($_POST['value'] == "1") { $sql = mysql_query("SELECT SQL_CACHE table1_relation_id FROM table2 WHERE field2 LIKE '$getquery' ORDER BY field2"); while ($row = mysql_fetch_array($sql)) { $idArray[] .= $row['table1_relation_id']; } mysql_free_result($sql); } //end if so basicy i just continue the array and it keeps pumping ids into a big aray. after that i run array_unique and remove all duplicate results and then i foreach and get the whole item info ased on every id. it runs pretty fast. now i would like to make the second one a function. but when i do that it does not work. Code: [Select] function sample($query, $table, $field) { $sql = mysql_query("SELECT SQL_CACHE naziv_id FROM ".$table." WHERE ".$field." LIKE '$query'"); while ($row = mysql_fetch_array($sql)) { $return[] .= $row['naziv_id']; } mysql_free_result($sql); return $return; } before i put it into a function $idArray vas a single continuous array. And if i try to do it like this: Code: [Select] $arr[] = sample($query, "table1", "filed_id"); $arr[] .= sample($query, "table2", "filed_id"); it returns the result of the first array ok but if there are more then one results in other arrays it returns and arary inside of the array. like this: Code: [Select] array(4) { [0]=> array(2) { [0]=> string(4) "9057" [1]=> string(5) "14186" } [1]=> string(5) "Array" [2]=> string(5) "Array" [3]=> string(0) "" } and all i wanna have is a single id variable that has all the id's in it. like $array = 1,2,3,4,5 but from different sources/functions can you help? thank you so much. Folks, I need help (Php code ) to generate a Dynamic Text on a Base Image. What i want to do is, to make this Image as header on my Site and to make this Header Specific to a Site, i want to Add the Domain Name on the Lower Left of the Image. Got the Idea? Here is the Image link: Quote http://img27.imageshack.us/i/shoppingheader1.jpg/ PHP Variable that holds the Domain name is: $domain All i need the Dynamic PHP Codes that i can put on all my sites to generate this Text on Image (Header) Dynamically... May Anyone Help me with this Please? Cheers Natasha T. <html> <?php $id = $_GET['id']; $dbusername="web148-matt"; $dbpassword="matt"; $dbdatabase="web148-matt"; mysql_connect(localhost,$dbusername,$dbpassword); @mysql_select_db($dbdatabase) or die( "Unable to select database"); mysql_query("UPDATE count SET clicks=clicks+1 WHERE id='$id'"); $sql = mysql_query("SELECT link FROM count WHERE id='$id'"); $fetch = mysql_fetch_row($sql); $result = mysql_query("SELECT * FROM count"); while($row = mysql_fetch_array($result)) { echo "<a href=" .$row['link']. ">Link</a>"; } ?> <a href='http://www.google.com'>Google</a> <a href='/index.php?id=2'>link2</a> </html> Hi all I need to combine these two scripts: Firstly, the following decides which out of the following list is selected based on its value in the mySQL table: <select name="pack_choice"> <option value="Meters / Pack"<?php echo (($result['pack_choice']=="Meters / Pack") ? ' selected="selected"':'') ?>>Meters / Pack (m2)</option> <option value="m3"<?php echo (($result['pack_choice']=="m3") ? ' selected="selected"':'') ?>>Meters / Pack (m3)</option> <option value="Quantity"<?php echo (($result['pack_choice']=="Quantity") ? ' selected="selected"':'') ?>>Quantity</option> </select> Although this works OK, I need it also to show dynamic values like this: select name="category"> <?php $listCategories=mysql_query("SELECT * FROM `product_categories` ORDER BY id ASC"); while($categoryReturned=mysql_fetch_array($listCategories)) { echo "<option value=\"".$categoryReturned['name']."\">".$categoryReturned['name']."</option>"; } ?> </select> I'm not sure if this is possible? Many thanks for your help. Pete ok, here is some code: Code: [Select] <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM products"); while($row = mysql_fetch_array($sql)){ $product = $row["product"]; ?> <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#myform").validate({ debug: false, submitHandler: function(form) { // do other stuff for a valid form $.post('process.php', $("#myform").serialize(), function(data) { $("#price").load("index.php #price"); $('#results').html(data); }); } }); }); </script> <form name="myform" id="myform" method="POST" action=""> <input type="hidden" name="hiddenField" id="hiddenField" value="<?php echo $product; ?>" /> <input type="submit" name="submit" value="Submit" style="background-color:lightgreen; height:50px; width:100px;"> </form> <?php } ?>and here is process.php Code: [Select] <?php include_once("/connect.php"); ?> <?php $price=$_POST['hiddenField']; $sql = "INSERT INTO cart (price) VALUES('$price')"; $rs = mysql_query($sql) or die ("Problem with the query: $sql<br>" . mysql_error()); echo mysql_error(); ?>. what is happening is it is supposed to be submitting form without page reload.......but only the first one in the loop does it. I want all of them to do it. can anyone help me do this properly. I am pulling data from an sql data base. I want it to displayed (Item # | Error button | Link) however as its looping with a while on the database info I cant seem to get it to loop on the item number so it shows 1, 2, 3,.... on each row. Current coding is: while ($info = mysql_fetch_array($data)){ Print '<tr>'; Print"<td style='width: 15px;' class='cat-list'>$D</td>"; if ($info['id']==""){ Print"<td class='cat-list'> </td>"; }else{ Print"<td class='cat-list' style='width: 20px;'><img border='0' src='images/error.png' width='16' height='16'></td>"; } if ($info['link']==""){ Print"<td class='cat-list'> </td>"; }else{ Print"<td class='cat-list'><a target='_blank' href='".html_entity_decode(stripslashes($info[link]))."'>".substr(html_entity_decode(stripslashes($info[link])), 0, 85)."</a></td>"; } } How would I get the $D item to show 1 2 3... ect? Thanks, Jim Take a look he http://answers.yahooapis.com/AnswersService/V1/questionSearch?appid=YahooDemo&query=test That is a generated XML file from Yahoo's API. If you take a look, it has a node titled "Question". With PHP, how can I loop through each "Question" node and grab all of it's children as well? I tried this code, but apparently it did not work: $req = "http://answers.yahooapis.com/AnswersService/V1/questionSearch?appid=YahooDemo&query=php"; $res = file_get_contents($req); $xml = simplexml_load_string($res); foreach ($xml->xpath('//Question') as $question) { // "//question" means for each question node echo((string)$question['Subject']." - ".(string)$question['Content']); // you get all the child nodes in $question } i have this bit of code which is supposed to do a while loop of rows from a database then inside that does a while loop of columns, so its basically creating a html table of dynamic data from mysql. the column loop works fine, but the row one isnt, it only goes through and echos out the first row then stops. ive spent hours now trying to see why and i cant see it hence my call for help. $totalrows = 4; $columns = 5; $columncount = 1; $rowcount = 1; echo "<table>"; while ($rowcount <= $totalrows) { echo "<tr>"; $sql = "SELECT * FROM ville_map WHERE id = '$rowcount'"; $sql_result = mysql_query($sql, $connection); while ($row = mysql_fetch_array($sql_result)) { $c1 = explode(',', $row["c1"]); $c2 = explode(',', $row["c2"]); $c3 = explode(',', $row["c3"]); $c4 = explode(',', $row["c4"]); $c5 = explode(',', $row["c5"]); while ($columncount <= $columns) { $arraynum = ${'c'.$columncount}; if ($arraynum[2] > 0) { $playerimage = '<img src="images/player' .$arraynum[2]. '.png"'; } else { $playerimage = ""; } echo '<td background="images/' .$arraynum[0]. '.jpg" width="50" height="50">' .$playerimage. '</td>' ; $columncount++; } } echo "</tr>"; $rowcount++; } ?> </table> any help would be much appreciated. Hey, I have the following code that gets the name of the course from the XML. XML Snippet Code: [Select] <?xml version="1.0"?> <courses> <course> <id>70</id> <name>Marketing and Social Media</name> <dates> <date> <instance_id>6747</instance_id> <location /> <course_type>Day</course_type> <date_available>2011/07/13</date_available> <time_start>9:30</time_start> <time_end>17:00</time_end> <availibility>7</availibility> <running_dates> <running_date>2011/07/13</running_date> <running_date>2011/07/14</running_date> </running_dates> </date> </dates> </course> <course> </courses> PHP Code: [Select] $dom = new DomDocument(); $dom->load("courses.xml"); $xp = new domxpath($dom); $titles = $xp->query("/courses/course/name"); foreach ($titles as $node) { print $node->textContent . " "; } This prints out the course name fine. My question is how Can i get the rest of the data from the same query. For example why cant I do something like.. Code: [Select] ... foreach ($titles as $node) { print $node->name. " "; print $node->time_start. " "; print $node->course_type. " "; etc.. } So I want to loop through get the name and assign the rest of the nodes in there to variables or something. How come this doesn't loop? Everything is in the while loop.
My database connection is in the included file you see to begin the code which is what db_conx refers to just to be clear. Database connection is not an issue nor is getting values. I just get the first one and nothing more. No looping taking place here.
What I miss?
require('includes/db_connect.php'); $query = "SELECT * FROM events ORDER BY displayorder ASC"; $result = mysqli_query($db_conx, $query); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $pid = $row["id"]; $title = $row["title"]; $date = $row["date"]; $info = $row["info"]; $linkTxt = $row["linkTxt"]; $link = $row["link"]; $message = "<div id='events_holder'><table width='500' border='0' cellspacing='0' cellpadding='10'> <form action='edit_event_parse.php' method='post'> <tr> <td class='prayer_title'>Title:</td> <td><input type='text' name='title' class='admin_input' value='" .$title."' /></td> </tr> <tr> <td class='prayer_title'>Date:</td> <td><input type='text' name='date' class='admin_input' value='".$date."' /></td> </tr> <tr> <td class='prayer_title'>Link Text:</td> <td><input type='text' name='linkTxt' class='admin_input' value='".$linkTxt."' /></td> </tr> <tr> <td class='prayer_title'>Link URL:</td> <td><input type='text' name='link' class='admin_input' value='".$link."' /></td> </tr> <tr> <td class='prayer_title'>Event Details:</td> <td><textarea name='info' cols='20' rows='10' class='admin_area'>".$info."</textarea></td> </tr> <tr> <td><input type='hidden' name='pid' value='".$pid."' /></td> <td><input name='submit' type='submit' value='Edit Event' class='admin_submit'/></td> </tr> </form> </table> <p> </p> <hr /> <p> </p> </div>"; }Thanks! ok I'm a bit stuck here were I would think something would work easily im getting an error. What I am trying to loop is.. $data="UPDATE ts12 SET djid='$_POST[TS0]' WHERE id=1"; $data="UPDATE ts12 SET djid='$_POST[TS1]' WHERE id=2"; This would go on for 84 id's. So I figured I could just loop this line so I only have to type it once. Right now I have it set up for just testing 7 ids and I have this code.... if ($edit == yes) { for ($i=0; $i < 7; $i++){ $n=($i+1); $data.="UPDATE ts12 SET djid='$_POST[TS$i]' WHERE id=$n"; } if (!mysql_query($data,$con)) die('Error: ' . mysql_error()); }else{} The error I am getting is... PHP Parse error: syntax error, unexpected T_VARIABLE, expecting ']' in dir/page on line 6 What am I doing wrong here? ANYONE WHO CAN HELP ME WITH MY LOOP? THIS IS THE CODE THANKS IN ADVANCE.
<?php $testTwo = 'bakit ayaw po gumana paulit ulit bakit'; $testOne = 'bakit paulit ulit bakit ulit'; $tTwo = explode(' ', $testTwo); $tOne = explode(' ', $testOne); echo"SIMILARITIES:</br>"; foreach($tOne as $first) { foreach($tTwo as $second) { if($second == $first) { echo $second.' '; } } echo"</br>"; } ?> THIS IS THE OUTPUT SIMILARITIES: bakit bakit paulit ulit bakit bakit ulit THIS IS MY EXPECTING OUTPUT. bakit paulit ulit bakit ulit lang I have a loop which works fine but before the loop I run a query which I store as $AlbumName From this array and within the loop I want to echo $AlbumName['album_name']; but obvisouly its not working. Can somebody please show me how to do it? <?php $qImage = "SELECT * FROM photos"; $rImage = mysql_query($qImage); $Array = mysql_fetch_array($rImage); $qAlbumName = "SELECT * FROM albums WHERE id =".$Array['album'].""; $rAlbumName = mysql_query($qAlbumName); $AlbumName = mysql_fetch_array($rAlbumName); while ($row_images = mysql_fetch_assoc($rImage) ) { ?> <?php echo $row_images['id']; echo $row_images['name']; echo $row_images['photo_description']; echo $AlbumName['album_name']; } ?> I have a select field in my join form which allows users to select one of my speicifed counties. In the table the county is link to a country. I am trying to echo in a select statement a loop of all the available counties in england. here is the code <?php $qGetCounty = "SELECT * FROM Counties"; $rGetCounty = mysql_query($qGetCounty); echo " <select name=\"County\"> <optgroup label=\"England\"> "; while ($county = mysql_fetch_assoc($rGetCounty)){ if($county['country']=='England') { echo " <option value= '{$county['county']}'>{$county['county']}</option> "; }} echo " <optgroup label=\"Wales\"> "; while ($county=='Wales'){ echo " <option value= '{$county['county']}'>{$county['county']}</option> "; } echo " <optgroup label=\"Scotland\"> "; while ($county=='Scotland'){ echo " <option value= '{$county['county']}'>{$county['county']}</option> "; } echo " </select> " ; ?> It is not erroring but also it is not worlking correctly. It shows all the counties in England and both the labels for scotland and wales but does not show any counties in these two areas. I am new to loops so do not know how to fix this. I have tried changing the line while ($county=='Wales') to while ($county = mysql_fetch_assoc($rGetCounty)) But this makes no difference I am trying to loop through the array that I have created to check to see if any of the dates in the array match the date I am passing (which is todays date) and then asks the user to consider making another booking. This is what I have so far but I am not sure how to finish it off: Code: [Select] $table_id = 'booking'; $query = "SELECT * FROM booking WHERE bookingDate = 'newDate'"; $result = mysql_query($query); $loop = $end_Time - $start_Time; echo $loop; while($row = mysql_fetch_assoc($result)){ if ($startTime || $end_Time == 'booking.startTime'){ echo "choose another booking"; }{ echo "booking is ok"; } I've been over it a few times and for some reason my results are being read out 2 times per row in the database. This error occurs consistently accross my scripts except for one, but for the life of me I can't work out how. Any help would be appreciated. I have a feeling this is rather basic and am sorry for asking something so trivial. Many thanks. GET ALL CS RESULTS PHP - FULL FILE Code: [Select] <?php include ('connect.php'); $cat = $_GET['id']; $sql = "SELECT ind_id, ind_name, cs_name, cs_value, quarter, fiscal_year FROM industry, customer_satisfaction, cs_value, time"; $result = mysqli_query($link, $sql); $output = mysqli_affected_rows($link); if (!$result) { $error_num = mysqli_errno($link); $error_desc = mysqli_error($link); include ('error.html.php'); exit(); } else { while ($industry_result = mysqli_fetch_array($result)) { $industry_results[] = array( 'ind_id' => $industry_result['ind_id'], 'ind_name' => $industry_result['ind_name'], 'cs_name' => $industry_result['cs_name'], 'cs_value' => $industry_result['cs_value'], 'quarter' => $industry_result['quarter'], 'fiscal_year' => $industry_result['fiscal_year'] ); } if (!$industry_results) { $error = '<p><i>Database Returned no Results.</i></p>'; } else { include ('all_cs_results.html.php'); } } ?> GET ALL CS RESULTS HTML OUTPUT - FULL FILE Code: [Select] <ul id="result_list" class="results_list"> <?php foreach ($industry_results as $industry_result): ?> <li id="cs_result"> <?php echo $industry_result['ind_id']; ?> </li> <li id="cs_result"> <?php echo $industry_result['ind_name']; ?> </li> <li id="cs_result"> <?php echo $industry_result['cs_name']; ?> </li> <li id="cs_result"> <?php echo $industry_result['cs_value']; ?> </li> <li id="cs_result"> <?php echo $industry_result['quarter']; ?> </li> <li id="cs_result"> <?php echo $industry_result['fiscal_year']; ?> </li> <?php endforeach; ?> </ul> JQUERY AJAX LAYER - CODE SNIPPET Code: [Select] $('#all_cs').click(function(){ $('#display').load('get_all_cs.php', function(){ })}); Im tring to pass 2 variables to a function that uses Curl through a loop. testfunction($id,$page) curl_setopt($ch, CURLOPT_URL, "testserver.com/index.php?id=$id&page=$page"); The problem is that the result works only the first time. When i pass $id=5 and $page 5 it works fine. But when its incremented by the loop where $id=10 and $page =6. Nothing seems to be displayed. Can anyone please tell me when i am doing wrong?? |