PHP - Echo Nothing?
Hi,
I have created a class "friendClass" and tried to echo it. It prints nothing without any errors, not sure what was it going on? Any helps would be appreciated! Code: [Select] class friendClass{ //attributes - variable public $name; public $sex; public $title; public $country; //methods - function public function eat(){} public function watch(){} public function drive(){} public function speak(){} } $friend1 = new friendClass; $friend2 = new friendClass; $friend3 = new friendClass; $friend4 = new friendClass; $friend1 -> name = "Bach"; $friend1 -> title = "Muscian"; $friend1 -> sex = "Male"; $friend1 -> country = "Germany"; $friend1 -> eat("Bread"); $friend1 -> speak("German"); $friend1 -> drive("Horse"); $friend1 -> watch("Beethoven"); echo "Name is: ".$friend1->name; Similar TutorialsOK, 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. I saw that <?=$var?> instead of <?php echo $var; ?> can be used for echo, does it work on every server? Code: [Select] <?php $sum_num = mysql_query("SELECT SUM(likes) as totallikes FROM facebook"); echo $sum_num; ?> i got this result Resource id #27 how to get a number only? 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 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 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 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. 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. 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). 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']; ?> Code: [Select] <span class="hotspot" onmouseover="tooltip.show('User ID :');" onmouseout="tooltip.hide();"> i want to know how to echo this above code I want to echo this div below but only if there is more than one of these fields missing. How would I go about this? <?php //only echo all of this if one or more of these fields does not exists so....... if () { echo" <div id=\"items_todo\"> <h3>Members Info</h3><br/> <ul>"; if (empty($User['address_L1'])) { echo "<li><a href=\"#\">Update Address</a></li>";} elseif (empty($User['intro'])) {echo "<li><a href=\"#\">About You</a></li>";} elseif (empty($User['profile_image'])){echo "<li><a href=\"#\">Add Profile Image</a></li>";} elseif (empty($User['Nickname'])){echo "<li><a href=\"#\">Add A Nickname</a></li>";} echo"</ul> </div>"; } ?> |