Alphabetical sorting help....
Moderator: General Moderators
Code: Select all
<?
if ((isset($_GETї'uname']) == true) && (isset($_GETї'poem']) == true))
{
// Tell the user it has been submitted (optional)
echo('Your comment has been posted.');
// Set Mysql Variables
$host = 'localhost';
$user = '***';
$pass = '***';
$db = 'haunted_poetry';
$table = 'dbpoems';
// Set global variables to easier names
$username = $_GETї'username'];
$poem = $_GETї'poem'];
// Connect to Mysql, select the correct database, and run teh query which adds the data gathered from the form into the database
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
$add_all = "INSERT INTO $table values("$username","$poem")";
echo $add_all;
mysql_query($add_all) or die(mysql_error());
}
else
{
echo $add_all;
// If the form has not been submitted, display it!
?>
<form method='get' action='<? echo $PHP_SELF; ?>'>
Username: <input type='text' name='username'><br><br>
Poem: <input type='text' name='poem'><br><br>
<input type='submit' value='Post your poems'>
</form>
<?
}
?>i think so im not for sure
but here is the script for poem.php
Code: Select all
<?php
// This function makes the alphabetic list which the links.
function drawAddressList() {
$seperator = "-";
// Loop through all 26 characters.
for ($i = 1; $i <= 26; $i++) {
$letter = chr($i + 64);
echo $seperator . "<a href='{$_SERVERї'PHP_SELF']}?letter={$letter}'>{$letter}</a>";
}
echo $seperator . '<br />';
}
// This function gets a parameter or the default.
function getParm($VariableName, $Default = '') {
return (isset($_GETї$VariableName])) ? $_GETї$VariableName] : $Default;
}
drawAddressList();
// Connect to MySQL - use your user name and password.
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// Connects to the database that has the user table.
$db_selected = mysql_select_db('db', $link);
if (!$db_selected) {
die ('Can''t use table : ' . mysql_error());
} else {
$letter = getParm('letter');
if ($letter != '') {
$letter_query = "SELECT * FROM `table` WHERE `username` REGEXP '^$letter.*' ORDER BY `username`";
$letter_result = mysql_query($letter_query);
if ($letter_result != false) {
while ($letter_row = mysql_fetch_assoc($letter_result)) {
// Do something in here with the rows you get.
// Maybe use the information from the user table to fill another recordset with the poems.
}
}
}
}
?>- smpdawg
- Forum Contributor
- Posts: 292
- Joined: Thu Jan 27, 2005 3:10 pm
- Location: Houston, TX
- Contact:
Two things.
You need to fix the database connection information (like user, password, database) in this script and also put some code inside the while that will display the information from the database. When I made this sample, I didn't add DB information because I didn't have it. Start by fixing this stuff up.
You need to fix the database connection information (like user, password, database) in this script and also put some code inside the while that will display the information from the database. When I made this sample, I didn't add DB information because I didn't have it. Start by fixing this stuff up.
Code: Select all
// Connect to MySQL - use your user name and password.
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// Connects to the database that has the user table.
$db_selected = mysql_select_db('db', $link);
if (!$db_selected) {
die ('Can''t use table : ' . mysql_error());
} else {
$letter = getParm('letter');
if ($letter != '') {
$letter_query = "SELECT * FROM `table` WHERE `username` REGEXP '^$letter.*' ORDER BY `username`";
$letter_result = mysql_query($letter_query);
if ($letter_result != false) {
while ($letter_row = mysql_fetch_assoc($letter_result)) {
// Do something in here with the rows you get.
// Maybe use the information from the user table to fill another recordset with the poems.
}well that script you just showed was already in the script..
<?php
// This function makes the alphabetic list which the links.
function drawAddressList() {
$seperator = "-";
// Loop through all 26 characters.
for ($i = 1; $i <= 26; $i++) {
$letter = chr($i + 64);
echo $seperator . "<a href='{$_SERVER['PHP_SELF']}?letter={$letter}'>{$letter}</a>";
}
echo $seperator . '<br />';
}
// This function gets a parameter or the default.
function getParm($VariableName, $Default = '') {
return (isset($_GET[$VariableName])) ? $_GET[$VariableName] : $Default;
}
drawAddressList();
// Connect to MySQL - use your user name and password.
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// Connects to the database that has the user table.
$db_selected = mysql_select_db('db', $link);
if (!$db_selected) {
die ('Can''t use table : ' . mysql_error());
} else {
$letter = getParm('letter');
if ($letter != '') {
$letter_query = "SELECT * FROM `table` WHERE `username` REGEXP '^$letter.*' ORDER BY `username`";
$letter_result = mysql_query($letter_query);
if ($letter_result != false) {
while ($letter_row = mysql_fetch_assoc($letter_result)) {
// Do something in here with the rows you get.
// Maybe use the information from the user table to fill another recordset with the poems.
}
}
}
}
?>
i have put that stuff in there if i didnt it would look like this..
*the script with the username, password, database selected*
http://www.hauntedgraveyard.net/Poetry/poems.php
*the script without the username, password, database selected*
http://www.hauntedgraveyard.net/Poetry/test.php
but since i did ti looks like this-A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z-
Warning: mysql_connect(): Access denied for user: 'username@localhost' (Using password: YES) in /home/haunted/public_html/Poetry/test.php on line 23
Could not connect: Access denied for user: 'username@localhost' (Using password: YES)
here is both links so you can see for yourself-A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z-
*the script with the username, password, database selected*
http://www.hauntedgraveyard.net/Poetry/poems.php
*the script without the username, password, database selected*
http://www.hauntedgraveyard.net/Poetry/test.php