Jump to content

dbs data retrieval


Justafriend

Recommended Posts

2 problems 1st one is of course the major one i was following a tutorial online and  ended up with this code

<html>
<head>
<title> Email List</head>
<style type="text/css">
table {
       border: 2px solid red
       background-color: #ffc;
       }

th {
      border-bottom: 5px solid#000;
      }
      
td {
    border bottom: 2px solid #666;
    }
</style>
</head>
<body>

<h1> Email List </h1>

<?php
$dbcon = mysql_connect("localhost","dbs_dbs","password","dbs_forms") or die("Can not connect: " . mysql_error());
$sqlget = "SELECT * From playersemails"
$sqldata = mysql_query ($dbcon, $sqlget)or die("Can not connect: " . mysql_error());

echo "<table>";
echo "<tr><th>Players Name</th><th>Email address></th></tr>
while($row = mysql_fetch_array($sqldata, MYSQL_ASSOC)) {

echo "<tr><td>";
echo $row[`playersname`];
echo </td><td>
echo $row[`email`];
echo "</td></tr>;
}
echo "</table>";
?>
</body>
</html>


now the problem is when i run it it just comes back with a blank page that is the first issue now also in this tutorial i also noticed that the results didnt come back alphabetical and if it is possible i would like to have my table alphabetical  by player name

Link to comment
Share on other sites

ok well looking further into it i found a simpler code and used it but now still need to get it to go alphabetical here is the new code



<html>



<body>



<?php



$db = mysql_connect("localhost", "dbs_dbs","dbs4evr");



mysql_select_db("dbs_forms",$db);



$result = mysql_query("SELECT * FROM playersemails",$db);



echo "<table border=1>";



echo "<tr><td>Players Name</td><td>Email</tr>";



while ($myrow = mysql_fetch_row($result)) {



		printf("<tr><td>%s</td><td>%s</td></tr>",

		$myrow[1], $myrow[2], $myrow[3]);



}



echo "</table>";



?>



</body>





</html>


Link to comment
Share on other sites

the first code you posted has a fatal php syntax error (you can see where it is at in the code because the syntax highlighting in your post stops changing colors.) you should set php's error_reporting to E_ALL and display_errors to on in your php.ini to get php to display all types of errors.

 


 

time for some mysql basics. the following is the syntax prototype for a SELECT query (it and a lot of useful information can be found in the mysql documentation at - http://dev.mysql.com/doc/refman/5.5/en/index.html ). i have highlighted the part of the syntax that would get the result set in alphabetical order (the default is ASC ascending) -

 

SELECT
[ALL | DISTINCT | DISTINCTROW ]
[HIGH_PRIORITY]
[sTRAIGHT_JOIN]
[sql_SMALL_RESULT] [sql_BIG_RESULT] [sql_BUFFER_RESULT]
[sql_CACHE | SQL_NO_CACHE] [sql_CALC_FOUND_ROWS]
select_expr [, select_expr ...]
[FROM table_references
[WHERE where_condition]
[GROUP BY {col_name | expr | position}
[ASC | DESC], ... [WITH ROLLUP]]
[HAVING where_condition]
[ORDER BY {col_name | expr | position}
[ASC | DESC], ...]
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
[PROCEDURE procedure_name(argument_list)]
[iNTO OUTFILE 'file_name'
[CHARACTER SET charset_name]
export_options
| INTO DUMPFILE 'file_name'
| INTO var_name [, var_name]]
[FOR UPDATE | LOCK IN SHARE MODE]]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.