PHP - Echo Issue
hello i have one issue
Code: [Select] <?php for($i=0;$i<=10;$i++){ echo $i; } ?> it echoes 0123445678910 but the thing is how i can do it like with numbers to echo just one line and ascendent from 0 to 10 like this " 23 of 10000 viewed " something like that Similar TutorialsEDIT: Solved. I was calling duplicate variables from an include. Changing the name in this code to something (could be anything really) different fixed the issue. Thanks!! I am currently working on some PHP which grabs variables from the link so I can keep track of which user has been clicked on. Everything seemed to be working just fine until I got to a particular part of the code. Let me know if this makes any sense AT ALL!!! As usual my code can be found below. Thanks!! Code: [Select] <?php session_start(); // Put stored session variables into local php variable $staff_id = $_SESSION['sid']; $staff_username = $_SESSION['username']; $staff_fname = $_SESSION['staff_first_name']; $cust_edit_access = $_SESSION['cust_edit_access']; include_once "scripts/connect_to_mysql.php"; $customer_id = $_GET['cid']; $customer_id = mysql_real_escape_string($customer_id ); $customer_id = eregi_replace("`", "", $customer_id); $customer_project_id = $_GET['pid']; $customer_project_id = mysql_real_escape_string($customer_project_id ); $customer_project_id = eregi_replace("`", "", $customer_project_id ); include "left_nav_customers.php"; include "left_nav_tools.php"; include "pgbdy_header_left.php"; include "project_display.php"; $sql = mysql_query("SELECT * FROM company_info WHERE proj_id='$customer_project_id'"); while ($row = mysql_fetch_array($sql)) { $company_name = $row["company_name"]; $customer_address = $row["address"]; $customer_city = $row["city"]; $customer_state = $row["state"]; $customer_zip = $row["zip"]; $customer_email = $row["email"]; $customer_phone = $row["phone"]; $customer_fax = $row["fax"]; $cust_pre_meth_contact = $row["pref_meth_contact"]; $cust_entry_date = $row["entry_date"]; } $temp_project_id = ''; $start_date = date("F j, Y, g:i:s a"); $start_month = date('n'); if ($_POST['create_new_customer_project']) { $sql2 = mysql_query("INSERT INTO projects (cust_id, staff_id, start_date) VALUES('$customer_id','$staff_id','$start_date')") or die (mysql_error()); // Get the inserted ID here to use in the activation email $new_project_id = mysql_insert_id(); // Create directory(folder) to hold each user files(pics, MP3s, etc.) $temp_project_id = "$start_month-00$customer_id-0$new_project_id"; mkdir("customer_files/cust$customer_id/$temp_project_id", 0755); $sql3 = mysql_query("UPDATE projects SET proj_id='$temp_project_id' WHERE id='$new_project_id'"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link rel="stylesheet" type="text/css" href="style.css"/> <!----------- ALL JAVASCRIPT ------------------------ ==================================================--> <script src="js/jquery-1.5.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> function toggleSlideBox(x) { if ($('#'+x).is(":hidden")) { $(".hiddenDiv").slideUp(200); $('#'+x).slideDown(300); } else { $('#'+x).slideUp(300); } } </script> <!--===========COMPANY INFO POPUP==============-- ==============================================--> <script type="text/javascript"> <!-- function edit_company_info() { window.open( "edit_company_info.php?sid=<?php echo "$staff_id"; ?>&cid=<?php echo "$customer_id"; ?>&pid=<?php echo "$customer_project_id"; ?>", "myWindow", "status = 1, toolbar = no, scrollbars = no, location = no, resizable = no, height = 580, width = 600, resizable = 0" ) } //--> </script> <!--===========COMPANY INFO POPUP==============-- ==============================================--> <!--===========GENERAL INFO POPUP==============-- ==============================================--> <script type="text/javascript"> <!-- function edit_general_info() { window.open( "http://www.google.com/", "myWindow", "status = 1, toolbar = no, scrollbars = no, location = no, resizable = no, height = 600, width = 600, resizable = 0" ) } //--> </script> <!--===========GENERAL INFO POPUP==============-- ==============================================--> <!--===========BILLING INFO POPUP==============-- ==============================================--> <script type="text/javascript"> <!-- function edit_billing_info() { window.open( "http://www.google.com/", "myWindow", "status = 1, toolbar = no, scrollbars = no, location = no, resizable = no, height = 600, width = 600, resizable = 0" ) } //--> </script> <!--===========BILLING INFO POPUP==============-- ==============================================--> <!--===========FACILITY INFO POPUP==============-- ==============================================--> <script type="text/javascript"> <!-- function edit_facility_info() { window.open( "http://www.google.com/", "myWindow", "status = 1, toolbar = no, scrollbars = no, location = no, resizable = no, height = 600, width = 600, resizable = 0" ) } //--> </script> <!--===========FACILITY INFO POPUP==============-- ==============================================--> <!--===========PRODUCT NEEDS INFO POPUP==============-- ==============================================--> <script type="text/javascript"> <!-- function edit_product_needs_info() { window.open( "http://www.google.com/", "myWindow", "status = 1, toolbar = no, scrollbars = no, location = no, resizable = no, height = 600, width = 600, resizable = 0" ) } //--> </script> <!--===========PRODUCT NEEDS INFO POPUP==============-- ==============================================--> <script type="text/javascript"> <!-- var sURL = unescape(window.location.pathname); function refresh() { window.location.href = sURL; } //--> </script> <!----------- ALL JAVASCRIPT ------------------------ ==================================================--> </head> <body> <div id="pg_container"> <!--HEADER SECTION--> <div id="header"> <div id="header_logo"></div> <div id="header_right"> Welcome <a href="template.php?id=<?php echo "$staff_id"; ?>"><?php echo $staff_fname; ?></a> | <a href="logout.php">Logout</a> </div> </div> <!--HEADER SECTION--> <!--PAGE CONTAINER--> <div id="pgbdy_container"> <div id="left_nav"> <div id="leftnav_header"></div> <div id="leftnav_bdy"> <div id="leftnav_content"> <div id="leftnav_customers"> <p> Select a Customer:<br /><br /> <?php echo "$list_customers"; ?> </p> </div> <hr /> <?php if($cust_edit_access == "1") { ?> <div id="leftnav_tools"> <p> <?php echo "$leftnav_links"; ?> </p> </div> <?php } else { ?> <div id="leftnav_tools"> <p> Edit Customers<br /><br /> You do not have access to edit customers. </p> </div> <?php } ?> </div> </div> </div> <div id="pgbdy"> <div id="bdy_header"></div> <div id="bdy_content_area"> <div id="bdy_content"> <div id="bdy_content_header"> <div id="bdy_content_selected_customer"> <p><?php echo "$contact_info_display"; ?></p> </div> <div id="bdy_content_current_projects"> <form action="customer_profile.php?sid=<?php echo "$staff_id"; ?>&cid=<?php echo "$customer_id"; ?>" method="post" enctype="multipart/form-data"> <p> Customer Projects <input name="create_new_customer_project" type="submit" class="create_new_customer_project_btn" value="" /><br /><br /> <?php echo "$list_customer_projects"; ?> </p> </form> </div> </div> <hr /> <div id="bdy_content_container"> <div id="company_information_section"> <a href="#" onclick="return false" onmousedown="javascript:toggleSlideBox('company_infoBox');">Company Information</a> <div class="hiddenDiv" id="company_infoBox" style="border:#FFF 2px solid; width:553px;"> <p>Please click the button below to edit the customer's company information.<br /> <input name="edit_company_info" onclick="edit_company_info()" type="button" value="Edit Company Information"/><br /><br /> //i placed this here just to make sure the issue was on this page. <?php echo "$customer_project_id"; ?> <b>Company Name: </b><?php echo "$company_name"; ?><br /> <b>Contact Name: </b><?php echo "$customer_fname"; ?> <?php echo "$customer_lname"; ?><br /> <b>Address: </b><?php echo "$customer_address"; ?><br /> <b>City, State, Zip: </b><?php echo "$customer_city"; ?>, <?php echo "$customer_state"; ?> <?php echo "$customer_zip"; ?><br /> <b>Email: </b><?php echo "$customer_email"; ?><br /> <b>Phone: </b><?php echo "$customer_phone"; ?><br /> <b>Fax: </b><?php echo "$customer_fax"; ?><br /> <b>Preferred Method of Contact: </b><?php echo "$cust_pre_meth_contact"; ?> </p> </div> </div> <div id="general_information_section"> <a href="#" onclick="return false" onmousedown="javascript:toggleSlideBox('general_infoBox');">General Information</a> <div class="hiddenDiv" id="general_infoBox" style="border:#FFF 2px solid; width:553px;"> <p>Please click the button below to edit the customer's general information.<br /> <input name="edit_general_info" onclick="edit_general_info()" type="button" value="Edit General Information"/> </p> </div> </div> <div id="billing_information_section"> <a href="#" onclick="return false" onmousedown="javascript:toggleSlideBox('billing_infoBox');">Billing Information</a> <div class="hiddenDiv" id="billing_infoBox" style="border:#FFF 2px solid; width:553px;"> <p>Please click the button below to edit the customer's billing information.<br /> <input name="edit_billing_info" onclick="edit_billing_info()" type="button" value="Edit Billing Information"/> </p> </div> </div> <div id="facility_information_section"> <a href="#" onclick="return false" onmousedown="javascript:toggleSlideBox('facility_infoBox');">Facility Information</a> <div class="hiddenDiv" id="facility_infoBox" style="border:#FFF 2px solid; width:553px;"> <p>Please click the button below to edit the customer's facility information.<br /> <input name="edit_facility_info" onclick="edit_facility_info()" type="button" value="Edit Facility Information"/> </p> </div> </div> <div id="product_needs_information_section"> <a href="#" onclick="return false" onmousedown="javascript:toggleSlideBox('product_needs_infoBox');">Product Needs Information</a> <div class="hiddenDiv" id="product_needs_infoBox" style="border:#FFF 2px solid; width:553px;"> <p>Please click the button below to edit the customer's product needs information.<br /> <input name="edit_product_needs_info" onclick="edit_product_needs_info()" type="button" value="Edit Product Needs Information"/> </p> </div> </div> </div> </div> </div> </div> <div id="right_nav"> <div id="rightnav_header"></div> <div id="rightnav_bdy"> <div id="rightnav_bdy_content"> <div id="rightnav_proj_status"> <p> All Current Associated Project Statuses </p> </div> <hr /> <div id="rightnav_alerts"> <p> Any associated alerts sent so far </p> </div> </div> </div> </div> </div> <!--PAGE CONTAINER--> <div id="footer"></div> </div> </body> </html> The issue is that each of these ID echo statements (cid being customer id, sid being staff id, and pid being project id) echoes something. CID echoes correctly, SID does as well. For some reason, PID only echoes the last project ID that was entered for that particular user. So for example, if I add a project to a user and im staff it would be like this: Staff ID = my Staff ID = 1 Customer ID = customer I am currently working on = 11 (in this case...just a random number for example sake) Project ID = the current month number (no zeroes)-00(current customer id being worked on)-0(current project ID from table) = 3-0011-042 If our example is saying that the latest addition is 3-0011-042, and I click on project 3-0011-038, for some reason (EVEN THOUGH MY WEB LINK HAS THE CORRECT PID which is 3-0011-038) it only echoes the last PID entered in the table. Its almost like its completely ignoring what I have in my address bar and looks directly at my tables latest entry....this has really screwed with my brainnnn!!! I can't seem to figure it out for the life of me. I don't even know how I could run a $_GET function and not get what I am asking for.....crazy. Please help guys!!!! Hello I have a from that updates a few things in the db, and uses "<?php echo $PHP_SELF;?>". The form does update everything fine, however that page does not reflect it. If I refresh the page manually I can see the new values. Is this a common thing, and can anything be done to fix this? 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']}; ?> So I need to echo a row from my database with php, but where i need to echo is already inside an echo. This is my part of my code: $con = mysql_connect("$host","$username","$password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("main", $con); $result = mysql_query("SELECT * FROM Vendor"); while($row = mysql_fetch_array($result)) { //I need to echo right here .................. but I get a blank page when I try this. Please Help. echo '<option value=$row['vendor_id']>'; echo $row['vendor_id']; echo '</option>'; } mysql_close($con); Result: A Blank page. Thanks in advance! I have a log system that allows 10 logs on each side(Left and right). I am trying to make it so that the left side has the 10 most recent logs, then the right as the next 10. Any ideas? Hi
I try to echo out random lines of a html file and want after submit password to whole content of the same html file. I have two Problems.
1st Problem When I echo out the random lines of the html file I don't get just the text but the code of the html file as well. I don't want that. I just want the text. How to do that?
for($x = 1;$x<=40;$x++) { $lines = file("$filename.html"); echo $lines[rand(0, count($lines)-1)]."<br>"; }I tried instead of "file("$filename.html");" "readfile("$filename.html");" But then I get the random lines plus the whole content. Is there anything else I can use instead of file so that I get the random lines of text without the html code?P.S file_get_contents doesn't work either have tried that one. 2nd Problem: As you could see in my first problem I have a file called $filename.html. After I submit the value of a password I want the whole content. But it is like the program did forget what $filename.html is. How can I make the program remember what $filename.html is? Or with other words how to get the whole content of the html file? My code: if($_POST['submitPasswordIT']){ if ($_POST['passIT']== $password ){ $my_file = file_get_contents("$filename.html"); echo $my_file; } else{ echo "You entered wrong password"; } }If the password isn't correct I get: You entered wrong password. If the password is correct I get nothing. I probably need to create a path to the file "$filename.html", but I don't know exactly how to do that. How do I echo the day from the db? It just displays day and I want it to display the day that was set. <select name="date_of_birth" id="date_of_birth"> <option value="">Day</option> <?php $isset = isset($_POST['date_of_birth']); for($day = 1; $day <= 31; ++$day) { echo '<option'; if ($isset && $_POST['date_of_birth'] === $day) { echo ' selected="selected"'; } echo ">${day}</option>\n\t\t\t\t\t\t"; } ?> </select> Hi I once found out how to do this 4 years ago but I lost my backups and memory on the matter. I want this xml to be echoed? out as it is. When I try the standard echo and print, I get the first two lines of the code in gray when I view the page's source. I get no xml at all. Code: [Select] <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE blah [ <!ELEMENT cart (title, items)> <!ELEMENT title (#PCDATA)> <!ELEMENT items (item)+> <!ELEMENT item (prive, deprive, onprive+)> <!ELEMENT security (#PCDATA)> <!ELEMENT answer (#PCDATA)> <!ATTLIST answer correct (yeah) #IMPLIED> ]> this is followed by the standard displaying of xml items could anyone help me over here? thanks in advance... Hi all I am trying to get the contents from an array using the below SQL query: $sql = mysql_query ("SELECT MAX (postage_world) FROM `basket` "); while ($row = mysql_fetch_array($sql)) { echo $row["id"]; echo $row["description"]; echo $row["postage_world"]; } I need the SQL query to find the highest value from the table and then echo out the results. The error I get is "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given" Many thanks for your help! Hi all, I have a page which simply pulls info from a database by id: <?php include ('connect.php'); $id = $_GET['id']; $query = mysql_query("SELECT * FROM JOBS WHERE id=$id"); if (!$query) { echo "Could not run query: " . mysql_error(); exit; } $row = mysql_fetch_row($query); { echo "<body><h3>" . $row[1]. "</h3>"; echo "<h4>" . $row[2] . "</h4>"; echo "<h4>" . $row[3] . "</h4>"; echo "<h5>Duties & Responsibilities:</h5><ul>"; echo "<li><strong>" . $row[4] . "</strong>" . $row[5] . "</li>"; echo "<li><strong>" . $row[6] . "</strong>" . $row[7] . "</li>"; echo "<li><strong>" . $row[8] . "</strong>" . $row[9] . "</li>"; echo "<li><strong>" . $row[10] . "</strong>" . $row[11] . "</li>"; } ?> However in some cases the rows in the database may only contain data upto row 6 for example, how would I go about coding this so that it only displays rows that exist. If row 6 exists then 7 always will too as the information is connected. I am manually added this stuff into phpmyadmin as I do not need a form as once it is complete then it will not need to be added to. Also row 8 and 9 may contain data but 6 and 7 may not Many Thanks I saw that <?=$var?> instead of <?php echo $var; ?> can be used for echo, does it work on every server? For some reason, I can only get 1 row to echo out when there are actually multiple rows in the database that should be echoing. Here is what I have: $result = mysql_query("SELECT * FROM boards WHERE boardname='$board' ORDER BY id LIMIT 10"); $post = mysql_fetch_assoc($result); echo stripslashes($post['message']) . "<br>\n" . " --- ".stripslashes($post['username']). " on ".stripslashes($post['time']) ."\n<hr width=90%>\n"; It pulls the one record great, but it only shows one record... I want to keep it to 10 records, thus the LIMIT in there (which I think I did right...), but it won't even show the ones in there right now (under 10, so that's not an issue yet). Hi, I can't figure out how to echo <br/> after 14 characters every line from text. Any idea's? Cyto Hi freaks, Yes im a noob... I have some data in a db that im echoing out, but the last row wont multiply? The rest works great... I have tried having the data as the following: 1.12 or 0.12 & I have tried having it as a var. Do I need to have a % in there somewhere? Im adding up all the data then I want to multiply by 12% (*$row['markup']) <?php echo $row['Stock1']*$row['qty']+$row['cutting']+$row['production']+$row['additional']+$row['pluscover']+$row['selfcover']*$row['markup'];?> any help would be appreciated. cuzzmunger. Hi Freaks, You guys helped me yesterday & now I have expanded on what I was doing & now need more help. From my limited knowledge I'm trying to add theses strings together. (I'm a printer) Its all adding up correctly until the end. *$row['markup'] is only multiplying the last string and not the complete echo...I have indicated the last string in blue. <?php echo ($row['laminating']*$row['qty'])+($row['Stock1']*$row['qty'])+($row['cutting']+$row['production']+$row['additional']+$row['pluscover']+$row['selfcover'])*$row['markup'];?> What I need to do is add up everything in red and * by my markup value (12%) <?php echo ($row['laminating']*$row['qty'])+($row['Stock1']*$row['qty'])+($row['cutting']+$row['production']+$row['additional']+$row['pluscover']+$row['selfcover'])*$row['markup'];?> any help would be appreciated! cuzzmunger Code: [Select] <?php $statisctis=("SELECT date_liked , COUNT(site_id) AS num_site_id FROM `liked` WHERE date_liked < CURDATE() AND date_liked > CURDATE() - INTERVAL 1 WEEK AND site_id='45' GROUP BY date_liked"); $result1 = mysql_query ($statisctis) or die(mysql_error()); ?> in php admin i get result like this date_liked num_site_id 2011-11-28 10:00:29 1 2011-11-29 05:03:17 1 2011-11-30 04:51:37 1 how to echo this in my page? Here i get a COUNT number only Code: [Select] <?php $sum_datas = mysql_result($result1, 0); echo $sum_datas['date_liked']; ?> What is the correct way to write an if/else statement within an echo? I need to alter this so that I can query to see what data is found and if not correct not to echo the rest of the statement. Code: [Select] echo '<td class="productbox"> <h1>' . $product_title . '</h1> </td>'; So from the above code which is echoed within the single quotes, what is the correct way to include an if else check on a value from the database. I know how its done, but just want to save time and write it the correct way within this. |