Alphabetical sorting help....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

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.
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

first of all alot of people learn that way but im not like other people i learn by other ways like showing more then they show is the way i learn...


but smpdawg i just ran into a warning::
Warning: Missing argument 2 for getparm() in /home/haunted/public_html/Poetry/poems.php on line 16
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you need to pass in the second argument to getParm()
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

or change getParm defination to

Code: Select all

function getParm($VariableName, $Default='') { 
  return (isset($_GETї$VariableName])) ? $_GETї$VariableName] : $Default;    
}
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

i fixed it on my own but thank you....
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

Well i finally got it somewhat going but im still running into problems for some reason :?: i keep running into a error

error
Parse error: parse error, unexpected T_VARIABLE in /home/haunted/public_html/Poetry/poetry.php on line 22
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 reason :?:
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

My normal declaration for that function would have had the $Default = "" but didn't make in this post for some reason. I guess that is what happens when you code late.
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

i dont know whats the problem is thats making the error but i can probably figure that one out but can someone help me figure out why the alphabet script isnt showing the stuff stored in database?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

*sigh* export of structure and some data please. Your current query as well.
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

here is the 2 scripts..

here is poems.php script

Code: Select all

<?php 

// This function makes the alphabetic list which the links. 
function drawAddressList() &#123; 
  $seperator = "-"; 

  // Loop through all 26 characters. 
  for ($i = 1; $i <= 26; $i++) &#123; 
    $letter = chr($i + 64); 
    echo $seperator . "<a href='&#123;$_SERVER&#1111;'PHP_SELF']&#125;?letter=&#123;$letter&#125;'>&#123;$letter&#125;</a>"; 
  &#125;  
  echo $seperator . '<br />'; 
&#125; 

// This function gets a parameter or the default. 
function getParm($VariableName, $Default) &#123; 
  return (isset($_GET&#1111;$VariableName])) ? $_GET&#1111;$VariableName] : $Default;    
&#125; 

drawAddressList(); 

// Connect to MySQL - use your user name and password. 
$link = mysql_connect('localhost', 'username', 'password'); 
if (!$link) &#123; 
   die('Could not connect: ' . mysql_error()); 
&#125; 

// Connects to the database that has the user table. 
$db_selected = mysql_select_db('database', $link); 
if (!$db_selected) &#123; 
   die ('Can''t use table : ' . mysql_error()); 
&#125; else &#123; 
 

  if ($letter != '') &#123; 
    $letter_query = "SELECT * FROM `dbUsers` WHERE `username` REGEXP '^$letter.*' ORDER BY `username`"; 
    $letter_result = mysql_query($letter_query); 
    if ($letter_result != false) &#123; 
       while ($letter_row = mysql_fetch_assoc($letter_result)) &#123; 
         // Do something in here with the rows you get. 
          // Maybe use the information from the user table to fill another recordset with the poems. 
       &#125; 
    &#125; 
  &#125;  
&#125; 

?>
here is poetry.php script

Code: Select all

<?
if(isset($_GET&#1111;'commented']))
&#123; 

// 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&#1111;'uname']; 
$poem = $_GET&#1111;'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());
&#125;
else
&#123;

// 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> 
<?
&#125;
?>
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

Wrong

Code: Select all

$add_all = 'INSERT INTO $table values('$username','$poem',''';
Maybe right

Code: Select all

$add_all = "INSERT INTO $table values("$username","$poem","")";
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")";
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

alright that fixed one of the problems but caused another one :evil: now when i click submit button it comes up page cant be displayed and this goes into the Address box
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?
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

Fix this

Code: Select all

<form method='get' action='<? echo'$PHP_SELF';
Should be this.

Code: Select all

<form method='get' action='<? echo $PHP_SELF;
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

fixed somewhat of that but still not putting it in the database :?: :!: :?:
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

Did you get any error message when the form was submitted?

If you don't speciify the field names in an INSERT query, you must add them all. So how many fields are in $table and what are they?
Post Reply