PHP - Php Echo Problem
Hi all,
I have this problem with an echo I have this code, what is working only not all of it, it request a database (ID) TID which is a catorgy. Now I need to TID to be in a place but can't to seem to get it. Here is the code: Code: [Select] <?php defined('_JEXEC') or die('Restricted access'); // no direct access ?> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script> <script type="text/javascript"> /* function changeActiveCategory(id,show) { var a_categoryname = "a_category"+id; if(show){ document.getElementById(a_categoryname).className = "active"+id; }else{ document.getElementById(a_categoryname).className = ""; } } */ function changeActiveType(id,show) { var a_typename = "a_type"+id; if(show){ document.getElementById(a_typename).className = "active"+id; }else{ document.getElementById(a_typename).className = ""; } } var markerGroups = { "1": [], "2": [], "3": [], "4": [], "5": []}; function toggleGroup(type) { for (var i = 0; i < markerGroups[type].length; i++) { var marker = markerGroups[type][i]; if (marker.getVisible()) { marker.setVisible(false); changeActiveType(type,false); } else { marker.setVisible(true); changeActiveType(type,true); } } } function changeActiveButton(id) { document.getElementById("idmap").className = "map"; document.getElementById("idsatellite").className = "satellite"; document.getElementById("idterrain").className = "terrain"; var dividname = "id"+id; document.getElementById(dividname).className = id+" "+id+"active"; } var map; var goHome = new google.maps.LatLng(<?php echo $DefaultLat;?>, <?php echo $DefaultLng;?>); function HomeControl(controlDiv, map) { controlDiv.style.padding = '0px 5px'; var controlUI = document.createElement('DIV'); controlUI.style.cursor = 'pointer'; controlUI.setAttribute("class","mapType"); controlDiv.appendChild(controlUI); var controlMap = document.createElement('DIV'); if(map.getMapTypeId()=='roadmap'){ controlMap.setAttribute("class","map mapactive"); }else{ controlMap.setAttribute("class","map"); } controlMap.setAttribute("id","idmap"); controlUI.appendChild(controlMap); var controlsatellite = document.createElement('DIV'); if(map.getMapTypeId()=='satellite'){ controlsatellite.setAttribute("class","satellite satelliteactive"); }else{ controlsatellite.setAttribute("class","satellite"); } controlsatellite.setAttribute("id","idsatellite"); controlUI.appendChild(controlsatellite); var controlterrain = document.createElement('DIV'); if(map.getMapTypeId()=='hybrid'){ controlterrain.setAttribute("class","terrain terrainactive"); }else{ controlterrain.setAttribute("class","terrain"); } controlterrain.setAttribute("id","idterrain"); controlUI.appendChild(controlterrain); google.maps.event.addDomListener(controlUI, 'click', function() { /*map.setCenter(goHome);*/ }); google.maps.event.addDomListener(controlMap, 'click', function() { map.setMapTypeId(google.maps.MapTypeId.ROADMAP); changeActiveButton('map'); }); google.maps.event.addDomListener(controlsatellite, 'click', function() { map.setMapTypeId(google.maps.MapTypeId.SATELLITE); changeActiveButton('satellite'); }); google.maps.event.addDomListener(controlterrain, 'click', function() { map.setMapTypeId(google.maps.MapTypeId.HYBRID); changeActiveButton('terrain'); /*map.setMapTypeId(google.maps.MapTypeId.TERRAIN);*/ }); } function initialize() { var latlng = new google.maps.LatLng(<?php echo $DefaultLat;?>, <?php echo $DefaultLng;?>); var myOptions = { zoom: <?php echo $MapDistance;?>, center: latlng, navigationControl:true, scaleControl:true, mapTypeControl: false, mapTypeId: google.maps.MapTypeId.HYBRID }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var homeControlDiv = document.createElement('DIV'); var homeControl = new HomeControl(homeControlDiv, map); homeControlDiv.index = 1; map.controls[google.maps.ControlPosition.RIGHT].push(homeControlDiv); var gmarkers = []; var htmls = []; <?php echo 'var ptooltip=new Array();'; echo 'var showhtml=new Array();'; if($items) { $p=0; foreach ($items as $item) { $link = LinkHelper::getLink('properties','showproperty','',$item->CYslug,$item->Sslug,$item->Lslug,$item->Tslug,$item->Pslug); $item->name=str_replace("'","\'",$item->name); echo "\n"."ptooltip[".$p."]=new Array( '".$item->id."','".$item->ref."','".$item->tid."','".$item->name."','".$link."');"."\n"; /*property details*/ if($item->imagename!=NULL){ $img=$item->imagename;}else{$img='noimage.jpg';} $myHtml=''; $myHtml.='<div id="propertydetail"><div class="title"><a href="'. $link.'" title="'.str_replace('"',' ',$item->name).'">'.$item->name.'</a></div><div class="image"><img src="images/properties/images/thumbs/'.$item->id.'/'.$img.'" alt="'.str_replace('"',' ',$item->name).'" width="100" height="75"></div><div class="text">'; if ($item->name_type) { $myHtml.=JText::_($item->name_type).'<br />'; } if ($item->address) { $myHtml.=JText::_($item->address).'<br />'; } $myHtml.='</div>'; $myHtml.='<div class="property_button">'; $myHtml.='<a class="BottomlnkDetail" href="'.$link.'" title="'.$item->id.'">Lees meer...</a>'; $myHtml.='</div>'; $myHtml.='</div>'; echo "\n"."showhtml[".$p."]='".$myHtml."';"."\n"; $myHtml=''; /*end property details*/ $p++; } } ?> var base_Icon=new Array(); base_Icon = '<?php echo JURI::base();?>modules/mod_prop_googlemap/img/beer.png'; <?php if($items) { $x=0; foreach ($items as $item) { ?> var myLatlng = new google.maps.LatLng(<?php echo $item->lat;?>,<?php echo $item->lng;?>); var marker = new google.maps.Marker({ position: myLatlng, map: map, icon: base_Icon }); /*alert (marker.number);*/ marker.setTitle('Klik voor meer info.'); attachSecretMessage(marker, <?php echo $x;?>); markerGroups[HIER MOET TID KOMEN].push(marker); <?php $x++; } } ?> function attachSecretMessage(marker, number) { var infowindow = new google.maps.InfoWindow( { content: showhtml[number], /* disableAutoPan: true,*/ size: new google.maps.Size(50,50) }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); /*showInContentWindow(showhtml[number]);*/ }); google.maps.event.addListener(infowindow, 'closeclick', function() { /*infowindow.close(map,marker); showInContentWindow(''); closeInContentWindow();*/ }); /* google.maps.event.addDomListener(controlterrain, 'click', function() { map.setMapTypeId(google.maps.MapTypeId.HYBRID); changeActiveButton('terrain'); }); */ } function showInContentWindow(text) { var sidediv = document.getElementById('content_window'); sidediv.style.visibility = "visible"; sidediv.innerHTML = text; } function closeInContentWindow() { var sidediv = document.getElementById('content_window'); sidediv.style.visibility = "hidden"; } } </script> <div class="prop_googlemap" style="width:960px; height:510px"> <div class="first"> <div class="second"> <div class="third"> <div id="map_canvas" style="width: 950px; height: 500px"></div> <div id="prop_googlemap_categories_all"> <div id="prop_googlemap_categories"> <ul class="categorys"> <li><a id="a_type1" class="active1" href="javascript:void(0)" onclick="toggleGroup('1');">Kroeg</a></li> <li><a id="a_type2" class="active2" href="javascript:void(0)" onclick="toggleGroup('2');">Discotheek</a></li> <li><a id="a_type3" class="active3" href="javascript:void(0)" onclick="toggleGroup('3');">Zaal</a></li> <li><a id="a_type4" class="active4" href="javascript:void(0)" onclick="toggleGroup('4');">test</a></li> </ul> </div> <div style="clear:both"></div> <div class="prop_googlemap_categories_bottom"></div> </div> <div id="content_window"></div> <div id="side_bar"></div> </div> </div> </div> </div> <script type="text/javascript"> initialize(); </script> <div style="clear:both"></div> As you can see he Code: [Select] markerGroups[THIS IS WHERE THE TID SHOULD COME].push(marker);where now it says: "THIS IS WHERE THE TID SHOULD COME" there needs to be a number ( 1 stands for a bar, 2 stands for a disco, 3 for something else. Now this is where I ask for the TID: Code: [Select] echo "\n"."ptooltip[".$p."]=new Array( '".$item->id."','".$item->ref."','".$item->tid."','".$item->name."','".$link."');"."\n"; But it can be me, but can't seem to get it working.... Can't seem to get the right code for "THIS IS WHERE THE TID SHOULD COME" anyone that could help me? Thanks! Similar TutorialsHello, I have this syntax on my header div Code: [Select] <p><a href="javascript:ajaxpage('shopcart.php', 'content');" class="difflink"><img src="../stock_photos/shopcart.png"><?php echo '<span class="text">'.writeShoppingCart().'</span>'; ?></a></p> but whatever I try it always output my echo in the next line instead of next to my picture file. How can I do it displayed at the same line? Thank you ok im building facebook app and im just back to php after months not touched it. this is the code: $image = $facebook->api_client->photos_get(null,null, echo $uid); print_r ($image); echo "<BR>"; echo $image[0]["src"]; the problem is that echo $uid i tried every variation and it does not work! i maybe forget something that i should have done? the $uid containing user id numbers so what i did wrong and if im not wrong i wanted the numbers($uid) Wrapped in quotation marks so i tried: echo ." $uid ". and alot of other please help tnx Hi, Im pretty new to php but im have trouble understanding why my script is doing this. Forgive me for silly mistakes! Im creating a login/register website and once the person has logged in they get a message saying "Successful login, welcome username!" The php checks against a database of users in an if statement to check if the password is correct and then prints out the message. But at the end of the message the echo is printing out a 1. I get that because the echo is in an if statement its return true or 1 but I cant get it to not print out the 1. code snippet is - if ($username==$dbusername&&$password==$dbpassword) { echo "Successful login, welcome!"; } Hope that makes sense. Thanks for the help. Neil Having problems with my script echo without form being completed yet. Any help would be appreciated. The echo that is outputting early is "You must enter a Session Name". Code: [Select] <html> <head> <title>ReH-0.1--Create a Session</title> </head> <body bgcolor="575757"> <center> <?php $error = "Could not connect to the database"; mysql_connect('localhost','root','') or die ($error); mysql_select_db('temp') or die ($error); //Set Variables $id = $_POST['id']; $table = $POST['table']; //Check for exsistence if (!$id or !$table) { echo "<font color='#ff0000'>You must enter a Session Name</font>"; } else { echo "Congrats!"; } ?> <h2 style="color:#fff">ReH-0.1 Password Encryption</h2><br><br> <font color="#fff">Before encrypting your password, a session must be started. We need you to enter a personal session name that you will remember so that you password is protected by this session.</font><br><br> <form action="session_start.php" method="POST"> <label for="id" style="color: #fff;">Session Name: <input type="text" maxlength="10" size="10" name="id"></label><br><br> <label for="table" style="color: #fff;">Session Name Confirmation: <input type="text" maxlength="10" size="10" name="table"></label><br><br> <input type="submit" value="Create Session"> </form> </center> </body> </html> This php file cant echo in the 2nd php code, can anyone help me about this? 1st php code to connect into the 2nd php code Code: [Select] <?php $Total = $Total + $Amount; } ?> </tr> <tr> <td colspan="3" align="Right">Total</td> <td align ="Center"><?php echo number_format($Total,2);?></td> </tr> 2nd php code Code: [Select] <?php $db = mysql_connect("localhost", "root", ""); mysql_select_db("vinnex",$db); $TransNo = $_POST['TransNo']; $Username = $_POST['Username']; $Date = $_POST['Date']; $Total = $_GET['Total']; echo $Total; $sqltransaction = " INSERT INTO transaction (TransNo, Username, Date, Total) VALUES ('$TransNo', '$Username', '$Date', '$Total')"; $resulttransaction = mysql_query($sqltransaction); ?> I cannot retrieve my records from my table, neither can I display them on my website. I do not even get any errors when I run the script on my site. Any help or tips would be greatly appreciated. My current php script is: // connection to database server $db_selected = mysql_select_db('database1', $dbc); if (!$db_selected) { die ('Can\'t use database1 : ' . mysql_error()); } $query = "SELECT * FROM chesstable ORDER BY chapter, lastname"; $result = mysql_query($query) or die('Could not connect' . mysql_error()); echo mysql_num_rows($result); If (!$result) { $message = 'Invalid query: ' . mysql_error(); $message = 'Whole query: ' . $query; die ($message); } while($row = mysql_fetch_assoc($result)) { echo $row['firstname'] . " " . $row['lastname'] . $row['chapter']; } mysql_free_result($result); mysql_close($dbc); ?> Hi im having trouble getting the below code to listen to my css margin settings. Just to clear up the server side of things, can anybody tell me wether or not im using the correct syntax in the code below? Code: [Select] else { echo("<p class=\"passed\">Thankyou for submiting your details, you will be added to our directory shortly</p>"); }} Hi Guys, I keep getting the following error: Parse error: syntax error, unexpected T_ECHO in /Applications/XAMPP/xamppfiles/htdocs/pet/petCatalog1.php on line 51 I have copied the code from a tutorial and cannot for the life of me work out what the problem is with line 51???? I have attached the file and pasted the code below. The real problem line is: echo "<tr><td valign='top' width='15%' style='font-weight: bold; font-size: 1.2em'\n" The full code is attached - btw, inserting the ">" does not help to fix it!! <?php /* Programme: PetCatalog.php * Desc: Lists all pet categories with radio buttons */ ?> <html> <head> <title>Select a Pet Category</title> </head> <body> <?php /* Database login info - Move to an Include */ $host="localhost"; $user="root"; $passwd=""; $dbname="information_schema"; /* Establishes a connection with the databse */ $cxn = mysqli_connect ($host, $user, $passwd, $dbname) or die ("Could not connect to the database JAMIE!"); /* SQL Query to select all categories of pet from the petType column in the pet table */ $query = "SELECT * FROM PetCatalog.petType ORDER BY petType"; $result = mysqli_query($cxn,$query) or die ("Unable to connect to the database JAMIE"); /* Echo of H1 & H2 above the pet table */ echo "<div style='margin-left: .lin'>\n <h1 style='text-align: center'>Pet Catalogue</h1>\n <h2 style='text-align: center'>The following categories of pets are now available</h2>\n"; /* Create form to diplay pet categories */ echo "<form action='ShowPets.php' method='POST'>\n"; echo "<table cellpadding='5' border='1'>"; $counter=1; while ($row = mysqli_fetch_assoc($result)) { extract ($row) echo "<tr><td valign='top' width='15%' style='font-weight: bold; font-size: 1.2em'\n" echo "<input type='radio' name='interest' value='$petType'\n"; if( $counter == 1 ) { echo "checked='checked'"; } echo ">$petType</td>"; echo "<td>$typeDescription</td></tr>"; $counter++; } echo "</table>"; echo "<p>input type='submit' value='Select Pet Type'> </form></p>\n"; ?> </body> </html> 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; ?> the line : echo $form['catcher_id'] gives me a dropdown list when i choose another item from the dropdown i want to do a few things but my code not working: $selected_catcher = $form['catcher_id']; foreach($selected_catcher as $val) { $catcher_name = $val->getName(); echo $catcher_name." ".$val->getId(); if ($catcher_name = "zed-catcher") { echo $form['service_code']->renderLabel(); echo $form['service_code']->renderError(); echo $form['service_code']; } } please help? thanks 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']}; ?> Hi all - I am a novice when it comes to PHP, but I have managed to use it successfully many times. I have an issue where I can not get a variable to echo when I am calling it from within a file that is using SSI. Here is a basic example that should explain it better. In the /index.php file: Code: [Select] <?php $photo1="photo1.jpg"; $photo2="photo2.jpg"; ?> <?php include('http://www.DOMAIN.com/includes/header.php'); ?> In the /header.php file: <img src="http://www.DOMAIN.com/photos/<?php echo $photo1; ?>"> When I try to echo $photo1 from within the /header.php file it simply does nothing, even though the variable is declared before the call for the include file. If I try to do the echo with the IMG tag from within the /index.php file, it works no problem -but that wont work without a MAJOR site redesign with how things are configured. Question is, why does this not work, and how can I fix it? Huge thanks from this Newb! 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? 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! 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 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, 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; |