PHP - How To Do Echo So Shows On More Page Refreshes
Need help with some whiles, etc., and .php page refreshes.
$num; Comes from mysql_num_rows from a database table's regular 'select'. And gets the row id numbers for every row that the id numbers are listed in order. $totalrows comes from another select but is select * instead. And pulls the total rows in the whole table instead there are 49 rows in the whole table. I'm trying to get the page to show 5 table rows at a time like the following, but then when the page is still open on next page refresh to show the next 5 rows and continue that way. This following: Quote PHP Code: <?php $i=$num; if ($num == 5); {echo "The number is " . $num . "<br />";} do {$i = $i + 5; echo "The number is " . $i . "<br />"; } while ($i<$totalrows); ?> Brings up these results: The row number is 10 The row number is 15 The row number is 20 The row number is 25 The row number is 30 The row number is 35 The row number is 40 The row number is 45 The row number is 50 Shows all these on the page at the same time. I'm trying to get these to only show the 5 rows after every page refresh instead. Please let me know how to do that, and whether it can be done without any cookies. I don't know if there is a better way to show the first 5 separate like I have it. Thank you very much for your help. Similar TutorialsHey all. I have a simple code for verifying some data. I have two echos from if statements. The first is if the text input is empty echo: HELLO. The second is if text input data is not found in database echo: NOPE. Now in the following code the second one works fine. But the problem is if I leave the field empty BOTH echos show. So if I leave the input empty instead of saying "HELLO" it says, "HELLONOPE". Yet the second one works fine and display only "NOPE" The other thing is if I switch the two echos to die instead, they work fine. Code: [Select] if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['id']) { echo "HELLO"; } // checks it against the database $check = mysql_query("SELECT * FROM emp WHERE id = '".$_POST['id']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { echo "NOPE"; } else { //if login good then redirect them to the members area $id = $_POST['id']; header("Location: somepage.php?id=$id"); } } else { // they are not logged in } <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <input type="text" name="id" maxlength="40"> <input type="submit" name="submit" value="Login"> </form> What am I doing wrong? Hi Guy's, I've recoded allot with 3 scripts i had to my disposal. I've fixed 95% and i'm proud allready, but stuck at the following code. It does'nt execute any errors and refreshes the page without uploading the picture to the desired folder. Also folders are'nt created. I've turned on error reporting at level -1, but those errors i fixed. Can you please help me out? note: this is a partial code of a tiny usermanagement 'cms'. Code: [Select] <?php //action: add picture for user ----------------------------------------------------------------------------- if (isset($_GET['editpic']) && isset($_GET['id'])) { $id = (int) $_GET['id']; if ($id == 0) { die("Invalid ID provided."); } $sql = "SELECT username FROM `users` WHERE `id`='".$_GET['id']."'"; $res = mysql_query($sql) or die(mysql_error()); //execution when completed the add picture form and pressed submit button --------------------- if (isset($_POST['addPic'])) { $row = mysql_fetch_assoc($res); $title = protect($_POST['title']); if(!$title) { echo "<script language=\"Javascript\" type=\"text/javascript\"> alert(\"You must choose a title for your picture!\") document.location.href='profilecp.php'</script>"; } $target = $row['username']; if(!is_dir($target)) @mkdir($target); $target = $target . '/pics'; if(!is_dir($target)) @mkdir($target); $target = $target."/".basename($_FILES['pics']['name']) ; $size = $_FILES['pics']['size']; $pic = $_FILES['pics']['name']; $type = $_FILES['pics']['type']; $sql2= "INSERT INTO `user_photos` (`profile_id`,`title`,`size`,`type`,`reference`) VALUES ('".$_GET['id']."','$title','$size','$type','$pic'); "; $res2 = mysql_query($sql2) or die(mysql_error()); if(move_uploaded_file($_FILES['pics']['tmp_name'], $target)) { echo "<script language=\"Javascript\" type=\"text/javascript\"> alert(\"Your picture has been uploaded\") document.location.href='profilecp.php'</script>"; } else { echo "<script language=\"Javascript\" type=\"text/javascript\"> alert(\"There was an error, try again\") document.location.href='profilecp.php'</script>"; } $target2 = $row['username']; $target2 = $target2 . '/pics'; $target2 = $target2 . '/thumbs'; if(!is_dir($target2)) @mkdir($target2); $target2 = $target2."/".basename($_FILES['pics']['name']) ; createthumb($target,$target2,150,150); } <!-----------------------ADD PICTURES-----------------------//--> <div class="dividerp"> <form enctype="multipart/form-data" method="POST" action="administrator.php?editpic&id=<?php echo $id;?>"><br/> <strong>Upload Pictures</strong><br/><br/> <div class="formElm"> <label for="title">Title</label> <input id="title" type="text" name="title" maxlength="32"><br/> </div> <div class="formElm"> <label for="file">File</label> <input id="file" type="file" name="pics" maxlength="255"><br/> </div> <input type="submit" name="picAdd" value="Add"> </form> </div> </div> </body> </html> }?> and the mysql tables: Code: [Select] CREATE TABLE `users` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , `first` VARCHAR( 32 ) NOT NULL , `last` VARCHAR( 32 ) NOT NULL , `username` VARCHAR(32) NOT NULL, `password` VARCHAR(255) NOT NULL, `email` VARCHAR(255) NOT NULL, `about` TEXT NOT NULL, `level` int(4) default '1' ) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=latin1; Code: [Select] CREATE TABLE `user_photos` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `profile_id` INT NOT NULL , `title` VARCHAR( 128 ) NOT NULL , `size` INT NOT NULL , `type` VARCHAR( 128 ) NOT NULL , `reference` VARCHAR( 255 ) NOT NULL ) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=latin1; Best regards, Martijn I have peice of code which is designed enter a question into a database and the username of the person who asks the question. However, the code enters <?php echo Array; ?> into the database and not 'Tom'. I am using the same code which inserts the category of the question in the database which works. But the username comes up as <?php echo Array; ?>. Does anyone know why it shows "array"? Code: [Select] if($loggedIn) { echo "Welcome, ".$user['username'].". <a href=\"logout.php\">Logout</a>. <table width='300' border='0' align='center' cellpadding='0' cellspacing='1'> <tr> <td><form name='form1' method='post' action='phpviewquestion.php'> <table width='100%' border='0' cellspacing='1' cellpadding='3'> <tr> <td colspan='3'><strong>Your Question</strong></td> </tr> <tr> <td width='71'>Question</td> <td width='6'>:</td> <td width='600' height='50'><input name='question' type='text' id='question'></td> <td width='71'>Notes</td> <td width='6'>:</td> <td width='600' height='50'><input name='notes' type='text' id='notes'></td> </tr> <tr> <td colspan='3' align='center'><input type='image' name='image' value='Submit' src='http://www.domain.co.uk/images/submitbutton.PNG' name='image' width='100' height='53'></td> <input name='category' type='hidden' value='Furniture' id='category' > <input name='questionmaker' type='hidden' value='<?php echo $username; ?>' id='questionmaker' > </tr> </table> </form> </td> </tr> </table> </div> " ; } else { echo "Please <a href=\"login.php\">Login</a>."; } ?>
<?php I'm a bit stumped here and as usual I'm sure it's something simple. I have an object that checks if a user is an admin. It works fine. But it the HTML below it is not getting displayed. Take a look. welcome.php session_start(); $user = new users(); if (!isset($_SESSION['username'], $_SESSION['imadmin']) || $user->is_admin($_SESSION['username'])==0) { header('Location: index.php'); } welcome.php is getting displayed without getting redirected to the index. But there's no HTML, just the URL to welcome.php in the bar. Anyone? Cheers! Friends, I developed a script in php & i tested the script before encoding & its working fine. After i encoded the script through ionCube PHP Encoder & uploaded in my server but the file shows only blank page. Its not executing after encoding. What is the problem ?? How to fix it ? Hi all, I've created a data-entry HTML page that posts to update.php. I am using mysql to store the data entered. When I enter data and hit "update database" button, the php file pops up and correctly shows the data entered, but the update.php file does not show that same data on another computer. I have checked the mysql database and it clearly shows that it the new data has been stored. Why isn't the data showing up on any other computer? I can provide codes as needed. Thanks. Richard Hi! I'd like to echo a text section from pageB.php to pageA.php Is it possible to mark it up somehow and tell the browser to echo the variable? I'm thinking something like this should work after some alteration: pageA: <?php echo pageb.php/variable; ?> pageB: <?php $variable = ***the content section I want to be displayed on pageA*** "; ?> I'd be very grateful if someone could help me out. (: Hey guys, I m not an expert in PHP but i want to learn php now. So the question is, So i have 2 machines that I want to communicate; let's say 192.168.1.5 and 192.168.1.7 And then, there is a php called test_main.php in 192.168.1.5, then test.php in 192.168.1.7 My goal is to call test.php and then capture the echo result... is it possible? kinda like: in test_main.php Code: [Select] <?php echo file_get_contents("http://192.168.1.7/test.php?test=123123"); ?> in test.php Code: [Select] <?php echo "HELLO WORLD!"; ?> so the output when i call test_main.php is "HELLO WORLD!" Thanks guys! Appreciate it P.S. Maybe the function that I m using is incorrect? Please let me know of another function to use? anyone know how to get rid of an echo when you hit refresh on the browser? My browser is remembering the echo from with in a if statement when refresh is hit even if the if statement remains false on refresh. I successfully build a form, and I have a few echo's which will echo out error messages when an input box is left empty. The echo messages used to be on the same page while I was using PHP_SELF, now that I've separated the script from the form it will now be shown on a new empty page and the user has to use the browser's navigators to navigate back. I'd still like to keep my script from the form separated for read-ability reasons, but I'd also like to have the echo messages outputted on the same page as the form. How can I do that? I'm a newbie, so excuse this basic question. P.S. If somebody can give me a tip how to position the echo messages in the design, I'd appreciate it a lot, because it sometimes messes up the design. Hello,
Hello, I am trying to echo a message before redirecting the visitor to another page. The destination is a variable. This is what i have so far: Code: [Select] <?php if (array_key_exists($_GET[id],$links)) { $red = $links[$_GET[id]]; header("HTTP/1.1 301 Moved Permanently;"); header("Refresh:3; url=$red"); echo "You will be redirected to.."; } else { header("Location: http://www.example.com"); } exit(); ?> The problem is that it works in Firefox, but not IE. In IE it will work if there is no message and no delay, like the code below: Code: [Select] <?php if (array_key_exists($_GET[id],$links)) { $red = $links[$_GET[id]]; header("HTTP/1.1 301 Moved Permanently;"); header("Location: $red"); } else { header("Location: http://www.example.com"); } exit(); ? Does anybody have any idea, what is wrong with this code? Thank you in advance! Hi,
I have this snippet in my page:
<?php echo $EM_Booking->get_price(true) * $EM_Booking->get_spaces(); ?>The page executes with no hitches except the price is not multiplied by the spaces. I get and echo of "0". I'm new to this. Any help would be greatly appreciated and thanks! i have built pages that paginate with 10 rows per page (some pages show more but for the moment i want to focus on this particular page)
//Define Some Options for Pagination $num_rec_per_page=10; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * $num_rec_per_page; $results = mysql_query("SELECT * FROM `ecmt_memberlist` WHERE toonCategory='Capital' AND oldMember = 0 ORDER BY CONCAT(MainToon, Name) LIMIT $start_from, $num_rec_per_page") or die(mysql_error()); $results_array = array(); while ($row = mysql_fetch_array($results)) { $results_array[$row['characterID']] = $row; }The above sets the variables for the pagination and below the results are echo with 10 rows per page then i show the pagination links: <?php $sql = "SELECT * FROM `ecmt_memberlist` WHERE toonCategory='Capital' AND oldMember = 0 ORDER BY CONCAT(MainToon, Name)"; $rs_result = mysql_query($sql); //run the query $total_records = mysql_num_rows($rs_result); //count number of records $total_pages = ceil($total_records / $num_rec_per_page); ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center"><div style="width:100%; text-align:center;"> <ul class="pagination"> <li class="selected"> <?php echo "<a href='capitalmember.php?page=1'>".'«'."</a> ";?> </li> <? for ($i=1; $i<=$total_pages; $i++) { echo "<li><a href='capitalmember.php?page=".$i."'>".$i."</a></li> "; }; ?> <li class="selected"> <? echo "<a href='capitalmember.php?page=$total_pages'>".'»'."</a> "; // Goto last page ?></li> </ul></div> <?php $pageNr = $page; // Get Current Page Number $from = $pageNr * $rowsPerPage; // 3 * 10 = 30 // 3 * 10 = 30 $to = $from + $rowsPerPage; // 30 + 10 = 40 echo $pageNr; /* Result: From page 30 to 40 */ ?></td> </tr> </table>this works great and shows me 10 results per page, what i need to work out and work on next is: echo the number of results above the records (for example: "showing records 1 to 10" and then on page 2 "showing records 11 to 21" and page 3 "showing records 22 to 32" how can i work out the maths for this echo? i was thinking along the lines of; <?php $pageNr = $page; // Gets Current Page Number $from = $pageNr * $rowsPerPage; // 3 * 10 = 30 $to = $from + $rowsPerPage; // 30 + 10 = 40 // Now Show Results echo $from; // Echo from echo $to // Echo to ?>but i'm still working on this.. then i need to look at shortening the amount of page links on the page if for example i have 500 records it shows me links 1 to 50 and eats up the page.... Appreciate any help and light onto my problems. Many thanks Edited by jacko_162, 11 January 2015 - 05:43 PM. Hi, I wonder if I somebody can help me I have three drop down lists which are populated from data thats stored in my sql database. I also have a table which is echoed from the database all on the same page. What i want to do is allow users to select values in the drop down lists which will then echo different results below in the table. Is this possible. So on page load it will show all of the info in the html table. Then when the user changes the drop downs and clicks submit it will change the query to something SELECT dropdown1 value FROM users where Dropdown2 = 1 AND Dropdown3 = 2 etc. Is this possible to display this information on the same page using the dropdown list or does it need to load a different page as the client side is trying to edit a server side script? If its possible please can someone give me an example. Thanks in advance Edd Here's the code, this is the PHP in my html contacts page (that IS in fact saved with a PHP extension): <div class = "centercontainer"> OK, have no idea what's going on... I've done this a million times... why wont this output!?? I must have a major brain meltdown and dont know it yet!!! Code: [Select] <?php // this echoes just fine: echo $_POST['testfield']; // but this wont echo: echo if (isset($_POST['testfield'])) { $_POST['testfield'] = $test; } echo $test; /// or even this DOESNT echo either!: $_POST['testfield'] = $test; echo $test; ?> Hi All, I'm trying to echo the response from an SLA query, the query works and returns the data when I test it on an SQL application.. but when I run it on my webpage it won't echo the result. Please help? <?php $mysqli = mysqli_connect("removed", "removed", "removed", "removed"); $sql = "SELECT posts.message FROM posts INNER JOIN threads ON posts.pid=threads.firstpost WHERE threads.firstpost='1'"; $result = mysqli_query($mysqli, $sql); echo {$result['message']}; ?> |