dean012 Posted October 11, 2013 Share Posted October 11, 2013 (edited) ok i done evrything i could but it came out = 1) { echo 'There are no entries inside the database'; } while($row = mysql_fetch_array($result)) { echo ''; echo ''; echo ''; echo ''; } echo ' ID Destination Difficulty '. $row['ID'].' '. $row['Destination'].' '. $row['Difficulty'].' '; ?> <?php /* This code establishes a connection with the database on the server. The mysql_connect accepts three parameters. The mysql_select_db attempts to select the database that data will be retrived from. It accepts two parameters, one is the name of the database and the other is the connection variable.*/ $connect=mysql_connect("localhost","root",""); $db_selected = mysql_select_db("assesment", $connect); $query = "SELECT bay of plenty.ID,bay of plenty. Destinations, bay of plenty. Difficulty"; $result = mysql_query($query) or die(mysql_error()); if(!mysql_affected_rows() >= 1) { echo 'There are no entries inside the database'; } while($row = mysql_fetch_array($result)) { echo '<tr>'; echo '<td>'. $row['ID'].'</td>'; echo '<td>'. $row['Destination'].'</td>'; echo '<td>'. $row['Difficulty'].'</td>'; } echo '</table>'; ?> Edited October 11, 2013 by dean012 Quote Link to comment Share on other sites More sharing options...
dean012 Posted October 11, 2013 Author Share Posted October 11, 2013 ? Quote Link to comment Share on other sites More sharing options...
Barand Posted October 11, 2013 Share Posted October 11, 2013 surely you must have got an error message from mysql_error()? Quote Link to comment Share on other sites More sharing options...
dean012 Posted October 11, 2013 Author Share Posted October 11, 2013 nope Quote Link to comment Share on other sites More sharing options...
Barand Posted October 11, 2013 Share Posted October 11, 2013 what is the name of the file that the code is in? Quote Link to comment Share on other sites More sharing options...
dean012 Posted October 11, 2013 Author Share Posted October 11, 2013 php im trying to select data from a database table  Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 11, 2013 Share Posted October 11, 2013 Are you running the code on a server that is configured with PHP? and is that the full complete code you have? Quote Link to comment Share on other sites More sharing options...
dean012 Posted October 11, 2013 Author Share Posted October 11, 2013 the complete code is <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="keywords" content="" /> <meta name="description" content="" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Yakity Yak</title> <link href='http://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet' type='text/css'> <link href='http://fonts.googleapis.com/css?family=Abel|Satisfy' rel='stylesheet' type='text/css'> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <p><!-- end #header --></p> <div id="header" class="container"> <div id="logo"> <h1><a href="#">Yakity Yak</a></h1> </div> <div id="menu"> <ul> <li class="current_page_item"><a href="file:///D:/blackpolish/homepage.php">Homepage</a></li> <li><a href="file:///D:/blackpolish/trip.php">Destinations</a></li> <li><a href="#">contact </a></li> <li><a href="#">Login</a></li> <li></li> <li></li> </ul> </div> </div> <blockquote> <blockquote> <p> <center><img src="../../Documents/Unnamed Site 2/IMG_1913.jpg" width="999" height="388" alt=""/></center> </p> </blockquote> </blockquote> <div id="page"> <div class="post"> <h2 class="title"><a href="#">Welcome to Yakity yak club</a></h2> <div class="entry"> <table border='1'> <tr> <th>ID</th> <th>Destination</th> <th>Difficulty</th> </div> <?php /* This code establishes a connection with the database on the server. The mysql_connect accepts three parameters. The mysql_select_db attempts to select the database that data will be retrived from. It accepts two parameters, one is the name of the database and the other is the connection variable.*/ $connect=mysql_connect("localhost","root",""); $db_selected = mysql_select_db("assesment", $connect); $query = "SELECT bay of plenty.ID,bay of plenty. Destinations, bay of plenty. Difficulty"; From ID, Destinations, Difficulty $result = mysql_query($query) or die(mysql_error()); if(!mysql_affected_rows() >= 1) { echo 'There are no entries inside the database'; } while($row = mysql_fetch_array($result)) { echo '<tr>'; echo '<td>'. $row['ID'].'</td>'; echo '<td>'. $row['Destination'].'</td>'; echo '<td>'. $row['Difficulty'].'</td>'; } echo '</table>'; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
dean012 Posted October 11, 2013 Author Share Posted October 11, 2013 actually i did this last year but because my xampp is not working and i have to redo this. i cant really remember what i did last year but this is the complete working code <!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 name = "description" content = "Wellington Real Estate"/> <meta name = "keywords" content = "home, housing, Karori, Mirimar, Te Aro, Thorndon, Farcourts, Jonnys, Relax"/> <title> Agents </title> <link rel = "stylesheet" type = "text/css" href = "assessment.css"/> </head> <body> <div id = "wrapper"> <div id = "container"> <div id = "banner"> <h1>The Wellington Real Estate Company</h1> </div> <div id = "left"> <a href = "Index.php">Home</a> <a href = "Agents.php">Agents</a> <a href = "Suburbs.php">Suburbs</a> </div> <div id = "right"> <br/> <h2>Listing of Houses by Agent</h2> <p>All our agents are currently listing a range of properties. Please click on one of the links to see that agent's listings: </p><br/> <h1> Farcouts </h1> <table border='1'> <tr> <th>Address</th> <th>Bedrooms</th> <th>Bathrooms</th> <th>Price</th> <th>Suburb</th> <?php /* This code establishes a connection with the database on the server. The mysql_connect accepts three parameters. The mysql_select_db attempts to select the database that data will be retrived from. It accepts two parameters, one is the name of the database and the other is the connection variable.*/ $connect=mysql_connect("localhost","root",""); $db_selected = mysql_select_db("ong_assessment", $connect); $query = "SELECT houses.Address, houses.Bedrooms, houses.Bathrooms, houses.Price, agents.Agent, suburb.Suburb FROM houses, suburb, agents WHERE houses.Suburb_ID = suburb.Suburb_ID AND agents.Agent_ID = houses.Agent_ID AND agents.Agent = 'Farcourts' ORDER BY `houses`.`Price` DESC , `houses`.`Suburb` ASC "; $result = mysql_query($query) or die(mysql_error()); if(!mysql_affected_rows() >= 1) { echo 'There are no entries inside the database'; } while($row = mysql_fetch_array($result)) { echo '<tr>'; echo '<tr>'; echo '<td>'. $row['Address'].'</td>'; echo '<td>'. $row['Bedrooms'].'</td>'; echo '<td>'. $row['Bathrooms'].'</td>'; echo '<td> $'. $row['Price'].'</td>'; echo '<td>'. $row['Suburb'].'</td>'; } echo '</table>'; ?> </div> </div> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
dean012 Posted October 11, 2013 Author Share Posted October 11, 2013 i tried to copy it but it wont work Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 11, 2013 Share Posted October 11, 2013 When you open your browser to run the PHP file what is the url you're using? Does the url start with http:// or file:// Quote Link to comment Share on other sites More sharing options...
dean012 Posted October 11, 2013 Author Share Posted October 11, 2013 file:///C:/Users/User/Desktop/htdocs/trip1.php Quote Link to comment Share on other sites More sharing options...
NiTx Posted October 11, 2013 Share Posted October 11, 2013 Sorry to say this but you clearly have no idea what you're doing. You're missing " " around your query. That to any basic php programmer would be obvious. I'd suggest you take the time to learn PHP before asking for help. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 11, 2013 Share Posted October 11, 2013 (edited)   file:///C:/Users/User/Desktop/htdocs/trip1.php That is why. You cannot fun PHP code directly in a web browser.  You need to have a server installed that is configured with PHP. You access the server via its url followed by your php file, for example http://server-address/file.php    actually i did this last year but because my xampp is not working Make sure you still have xampp installed? Run xampp and put into your web directory (I think its C:\xampp\htdocs) and then go to http://localhost/ to run your PHP code. Edited October 11, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
dean012 Posted October 11, 2013 Author Share Posted October 11, 2013 when i mean not workingi mean its courrupted. and i tried localhost/trip1.php it came out Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\Users\User\Desktop\Desktop\htdocs\trip1.php on line 6 Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 11, 2013 Share Posted October 11, 2013 (edited)   when i mean not workingi mean its courrupted. What do you mean by that? What is corrupted, xampp comes with many components, such as apache, PHP, MySQL, phpMyadmin etc. Which of these are you saying is corrupted?    and i tried localhost/trip1.php it came out Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) inC:\Users\User\Desktop\Desktop\htdocs\trip1.php on line 6 There is an error on line 6 of trip.php. PHP cannot continue, unless you fix that error. What is trip.php? Edited October 11, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Solution dean012 Posted October 11, 2013 Author Solution Share Posted October 11, 2013 I SOLVED IT WOOHOO...this is the working code thx guys <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="keywords" content="" /> <meta name="description" content="" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Yakity Yak</title> <link href='http://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet' type='text/css'> <link href='http://fonts.googleapis.com/css?family=Abel|Satisfy' rel='stylesheet' type='text/css'> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <p><!-- end #header --></p> <div id="header" class="container"> <div id="logo"> <h1><a href="#">Yakity Yak</a></h1> </div> <div id="menu"> <ul> <li class="current_page_item"><a href="file:///D:/blackpolish/homepage.php">Homepage</a></li> <li><a href="file:///D:/blackpolish/trip.php">Destinations</a></li> <li><a href="#">contact </a></li> <li><a href="#">Login</a></li> <li></li> <li></li> </ul> </div> </div> <blockquote> <blockquote> <p> <center><img src="../../Documents/Unnamed Site 2/IMG_1913.jpg" width="999" height="388" alt=""/></center> </p> </blockquote> </blockquote> <div id="page"> <div class="post"> <h2 class="title"><a href="#">Taranaki</a></h2> <div class="entry"> <table border='1'> </div> </body> </html> <?php /* This code establishes a connection with the database on the server. The mysql_connect accepts three parameters. The mysql_select_db attempts to select the database that data will be retrived from. It accepts two parameters, one is the name of the database and the other is the connection variable.*/ $con=mysqli_connect("localhost","root","","assesment"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT * FROM taranaki"); echo "<table border='1'> <tr> <th>ID</th> <th>Destination</th> <th>Difficulty</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ID'] . "</td>"; echo "<td>" . $row['Destination'] . "</td>"; echo "<td>" . $row['Difficulty'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.