Alphabetical sorting help....
Moderator: General Moderators
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
I honestly advise you Smackie, get your PHP manual and read up all section and try all examples. try a little tweaking in them, then again try them out. That way you learn a lot and firm your hold on the matter. If possible grab a good book on PHP for yourself. Maybe a 21-dayer or something like that.
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
or change getParm defination to
Code: Select all
function getParm($VariableName, $Default='') {
return (isset($_GETї$VariableName])) ? $_GETї$VariableName] : $Default;
}Well i finally got it somewhat going but im still running into problems for some reason
i keep running into a error
error
error
and i made a field to see if the alphabet script would work but it doesnt it only shows the alphabet and non of the stuff in the database for some reasonParse error: parse error, unexpected T_VARIABLE in /home/haunted/public_html/Poetry/poetry.php on line 22
here is the 2 scripts..
here is poems.php script
here is poetry.php script
here is poems.php script
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('database', $link);
if (!$db_selected) {
die ('Can''t use table : ' . mysql_error());
} else {
if ($letter != '') {
$letter_query = "SELECT * FROM `dbUsers` 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.
}
}
}
}
?>Code: Select all
<?
if(isset($_GETї'commented']))
{
// Tell the user it has been submitted (optional)
echo('Your comment has been posted.');
// Set Mysql Variables
$host = 'localhost';
$user = 'username';
$pass = 'password';
$db = 'database';
$table = 'db table';
// Set global variables to easier names
$username = $_GETї'uname'];
$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',''';
mysql_query($add_all) or die(mysql_error());
}
else
{
// If the form has not been submitted, display it!
?>
<form method='get' action='<? echo'$PHP_SELF'; ?>'>
Name : <input type='text' name='username'><br><br>
Comment : <input type='text' name='poem'><br><br>
<input type='hidden' name='commented' value='set'>
<input type='submit' value='Post your comment'>
</form>
<?
}
?>- smpdawg
- Forum Contributor
- Posts: 292
- Joined: Thu Jan 27, 2005 3:10 pm
- Location: Houston, TX
- Contact:
Wrong
Maybe right
Is there really a 3rd field in the database that you want to be blank? If not, use this instead.
Code: Select all
$add_all = 'INSERT INTO $table values('$username','$poem',''';Code: Select all
$add_all = "INSERT INTO $table values("$username","$poem","")";Code: Select all
$add_all = "INSERT INTO $table values("$username","$poem")";alright that fixed one of the problems but caused another one
now when i click submit button it comes up page cant be displayed and this goes into the Address box
and any tips on fixing up the poem.php page?
it shouldnt send it to another page it should be sending it to the database and the page should go direct to the poem.php page...
and any tips on fixing up the poem.php page?
- smpdawg
- Forum Contributor
- Posts: 292
- Joined: Thu Jan 27, 2005 3:10 pm
- Location: Houston, TX
- Contact:
Fix this
Should be this.
Code: Select all
<form method='get' action='<? echo'$PHP_SELF';Code: Select all
<form method='get' action='<? echo $PHP_SELF;