Reply
a smal page making script.
Old 07-13-2004, 09:25 AM
aog
Skilled Talker

Posts: 62
Location: Norway, Bergen
I see you use first, last, phone, ect. as the names on your form. Do you use that becouse the table have rows called the same? so when you use $first','$last','$phone' in the insert.php, the value of $first','$last','$phone' will be added to the rows first, last, phone?
aog is offline
Reply With Quote
View Public Profile
 
Old 07-13-2004, 09:46 AM
Veter's Avatar
Super Talker

Posts: 136
Thats correct
__________________
-= B2Netsolutions Inc. =-
-= Dedicated servers - Shoutcast hosting =-
Veter is offline
Reply With Quote
View Public Profile Visit Veter's homepage!
 
Old 07-13-2004, 10:04 AM
aog
Skilled Talker

Posts: 62
Location: Norway, Bergen
k


One more question.
Lets say I have the rows "Item", "Items Type", "Ql", "Price", ect.

Then I want to post my info in the database. I could use what you showed me Veter, but what if I want to post the data sorted by "Items Type", and then "Items".
how whould I do that?

(I whould like it to look some thing like this
Quote:
Items Type: <a value of item type>

Items: Ql: Price:
Boots 23 500$


Items Type: <a new value>
ect

Last edited by aog : 07-13-2004 at 10:07 AM.
aog is offline
Reply With Quote
View Public Profile
 
Old 07-13-2004, 01:10 PM
aog
Skilled Talker

Posts: 62
Location: Norway, Bergen
Quote:
mysql_connect("69.49.230.13",$username,$password);

Why the ip?
Is that the localhost?
I can't connect to my databse.
Can I use localhost?
On the server "admin page" it says: "MySQL 4.0.16 runing on localhost as housemaa_vingtor@localhost"
I have tryed
a. ($host,$username,$password)
b. ($username,$host,$password)
c. ($password,$host,$username)
d. ($username,$password,$host)
e. ($password,$username,$host)


Nothing works

Last edited by aog : 07-13-2004 at 01:14 PM.
aog is offline
Reply With Quote
View Public Profile
 
Old 07-13-2004, 01:55 PM
Average Talker

Posts: 16
there is alot of information on php.net ,like the online manual. I virtually learned everything I can form there. Spend some time reading there, and try it out. Dont get too complicated too fast... There is information at mysql.com too.
__________________
-=nestyra.com=-
nestyra is offline
Reply With Quote
View Public Profile
 
Old 07-13-2004, 05:07 PM
aog
Skilled Talker

Posts: 62
Location: Norway, Bergen
ok..
Thanks to David Gowans I have now learned a lot about building databses.

There is still some questions I need aswer to.
I'll start with question 1.

I know how I can sort the data in a table using "ORDER BY".
But can I sort sort lik this:

my table.
__________________
row1 row2 row3 row4
aaaa 1111 aaaa aaaa
bbbb 1111 bbbb bbbb
bbbb 2222 bbbb bbbb
cccc 3333 cccc cccc


how I want it to look:

row2 1111
_____________
row1 row3 row4
aaaa aaaa aaaa
bbbb bbbb bbbb

row2 2222
_____________
row1 row3 row4
bbbb bbbb bbbb

row2 3333
_____________
row1 row3 row4
cccc cccc cccc


Can that be done, or do I have to put all row2 in a own table like below, and then use "ORDER BY" on each table and out put it on my webpage?

table 1111
_____________
row1 row2 row3
aaaa aaaa aaaa
bbbb bbbb bbbb


table 2222
_____________
row1 row2 row3
bbbb bbbb bbbb


table 3333
_____________
row1 row2 row3
cccc cccc cccc


EDIT:
Ok, I can fix the problem I just wrote about by making more tables.

But what I don't understand now, is why don't this work?
$query=" SELECT * FROM contacts WHERE id='1'";
I have a row called "id", and I have the value "1" in that row.
Should it not work?
The error I get it:
Quote:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result

Last edited by aog : 07-13-2004 at 06:21 PM.
aog is offline
Reply With Quote
View Public Profile
 
Old 07-14-2004, 03:34 PM
aog
Skilled Talker

Posts: 62
Location: Norway, Bergen
Ok..

I think this will be the last question.

What I can do now is:

- Creat a databse
- Create a table
- Add a record to a table
- Edit a record
- Delete a record
- Output a table
- Output from a table were $field holds the $info
- Sort the output of a table
- Search in a table


What I need to do is this:

$query="SELECT * FROM contacts WHERE first LIKE '%$search%' ORDER BY first, last ASC";
If there is nothing in the database, then I want to echo "No match was found. Pleace try again."

How do I do that?



Btw Veter, Thank you for making me do this!
I have learned SO much. Thank you.
aog is offline
Reply With Quote
View Public Profile
 
Old 07-14-2004, 03:46 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Perform a query then call the mysql_num_rows() function on the result.


PHP Code:
<?php

$link 
mysql_connect("localhost""mysql_user""mysql_password");
mysql_select_db("database"$link);

$query "SELECT * FROM contacts WHERE first LIKE '%$search%' ORDER BY first, last ASC"

$result mysql_query($query$link);
$num_rows mysql_num_rows($result);

if( 
$num_rows == )
{
    print 
"No match was found. Please try again." 
}
else
{
    
// Go do something amazing with your data!
}

?>
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 07-14-2004, 04:08 PM
aog
Skilled Talker

Posts: 62
Location: Norway, Bergen
Sweet!
aog is offline
Reply With Quote
View Public Profile
 
Old 07-14-2004, 06:28 PM
aog
Skilled Talker

Posts: 62
Location: Norway, Bergen
doh..


What is it I can't see...

This wont give me the same information as the script on the bottom.

Not working...
Quote:
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts WHERE first LIKE '%$search%' ORDER BY first, last ASC";
$result = mysql_query($query);
$num_rows = mysql_numrows($result);

mysql_close();

?>

<?
if( $num_rows == 0 )
{
echo ("No match was found. Please try again.");
}
elseif( $num_rows >= 1 )
{
echo ('Serach ressult for "'."$search".'"');
echo ('<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Phone</font></th>
<th><font face="Arial, Helvetica, sans-serif">Mobile</font></th>
<th><font face="Arial, Helvetica, sans-serif">Fax</font></th>
<th><font face="Arial, Helvetica, sans-serif">E-mail</font></th>
<th><font face="Arial, Helvetica, sans-serif">Website</font></th>
<th><font face="Arial, Helvetica, sans-serif"></font></th>
</tr>');

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web");
}

echo ('
<tr>
<td><font face="Arial, Helvetica, sans-serif">'."$first".' '."$last".'</font></td>
<td><font face="Arial, Helvetica, sans-serif">'."$phone".'</font></td>
<td><font face="Arial, Helvetica, sans-serif">'."$mobile".'</font></td>
<td><font face="Arial, Helvetica, sans-serif">'."$fax".'</font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="mailto:'."$email".'">E-mail</a></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="'."$web".'">Website</a></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="delete.php?id='."$id".'">Delete</a></font></td>
</tr>');

?>
<?
$i++;
}


echo "</table>";


?>
Working
Quote:
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts WHERE first LIKE '%$search%' ORDER BY first, last ASC";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();


echo ('<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Phone</font></th>
<th><font face="Arial, Helvetica, sans-serif">Mobile</font></th>
<th><font face="Arial, Helvetica, sans-serif">Fax</font></th>
<th><font face="Arial, Helvetica, sans-serif">E-mail</font></th>
<th><font face="Arial, Helvetica, sans-serif">Website</font></th>
<th><font face="Arial, Helvetica, sans-serif"></font></th>
</tr>');

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web");

echo ('<tr>
<td><font face="Arial, Helvetica, sans-serif">'."$first".' '."$last".'</font></td>
<td><font face="Arial, Helvetica, sans-serif">'."$phone".'</font></td>
<td><font face="Arial, Helvetica, sans-serif">'."$mobile".'</font></td>
<td><font face="Arial, Helvetica, sans-serif">'."$fax".'</font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="mailto:'."$email".'">E-mail</a></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="'."$web".'">Website</a></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="delete.php?id='."$id".'">Delete</a></font></td>
</tr>');

$i++;
}


echo ('</table>');


?>

The one that don't work is only giving out 1 person from the database, and only prints the 3 last rows. (E-mail, website and delete)

What am I doing wrong?
I can't seem to find the error..
I'm sure I'll scream out "Doh! That was it. How stupid of me not to see that" when you show me the error.. hehe
aog is offline
Reply With Quote
View Public Profile
 
Old 07-14-2004, 06:30 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
aog,

Not sure why, but your script is using mysql_numrows() instead of mysql_num_rows(). Maybe it is a variant I'm not aware of.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 07-14-2004, 06:33 PM
aog
Skilled Talker

Posts: 62
Location: Norway, Bergen
well..
I don't know either
but, mysql_numrows() works in the other script.
(the script who don't give a messag if nothing was found when searching.)
aog is offline
Reply With Quote
View Public Profile
 
Old 07-14-2004, 06:39 PM
Veter's Avatar
Super Talker

Posts: 136
lol. put mysql_close(); at the bottom of the page
__________________
-= B2Netsolutions Inc. =-
-= Dedicated servers - Shoutcast hosting =-
Veter is offline
Reply With Quote
View Public Profile Visit Veter's homepage!
 
Old 07-14-2004, 06:43 PM
aog
Skilled Talker

Posts: 62
Location: Norway, Bergen
well... the ressult is still the same.
aog is offline
Reply With Quote
View Public Profile
 
Old 07-14-2004, 06:54 PM
Veter's Avatar
Super Talker

Posts: 136
Hmm. Here is how would i did:
Quote:
$row = mysql_fetch_assoc($result);
$num = mysql_num_rows($result);
And you can use your variables like $row['id'], $row['first'], etc. instead of
Quote:
$id=mysql_result($result,$i,"id");
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web");
and

Quote:
<?php do { ?>
echo ('<tr>
<td><font face="Arial, Helvetica, sans-serif">'."$first".' '."$last".'</font></td>
<td><font face="Arial, Helvetica, sans-serif">'."$phone".'</font></td>
<td><font face="Arial, Helvetica, sans-serif">'."$mobile".'</font></td>
<td><font face="Arial, Helvetica, sans-serif">'."$fax".'</font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="mailto:'."$email".'">E-mail</a></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="'."$web".'">Website</a></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="delete.php?id='."$id".'">Delete</a></font></td>
</tr>');
<?php } while ($row = mysql_fetch_assoc($result)); ?>
__________________
-= B2Netsolutions Inc. =-
-= Dedicated servers - Shoutcast hosting =-
Veter is offline
Reply With Quote
View Public Profile Visit Veter's homepage!
 
Old 07-14-2004, 07:08 PM
Veter's Avatar
Super Talker

Posts: 136
This one is correct for your code
Quote:
<?php do {
echo "<tr>
<td><font face='Arial, Helvetica, sans-serif'>".$row['first']." ".$row['last']."</font></td>
<td><font face='Arial, Helvetica, sans-serif'>".$row['phone']."</font></td>
<td><font face='Arial, Helvetica, sans-serif'>".$row['mobile']."</font></td>
<td><font face='Arial, Helvetica, sans-serif'>".$row['fax.']"</font></td>
<td><font face='Arial, Helvetica, sans-serif'><a href='mailto:".$row['email']."'>E-mail</a></font></td>
<td><font face='Arial, Helvetica, sans-serif'><a href='".$row['web']."'>Website</a></font></td>
<td><font face='Arial, Helvetica, sans-serif'><a href='delete.php?id=".$row['id']."'>Delete</a></font></td>
</tr>";
} while ($row = mysql_fetch_assoc($result)); ?>
__________________
-= B2Netsolutions Inc. =-
-= Dedicated servers - Shoutcast hosting =-
Veter is offline
Reply With Quote
View Public Profile Visit Veter's homepage!
 
Old 07-14-2004, 07:31 PM
aog
Skilled Talker

Posts: 62
Location: Norway, Bergen
hmm...

now I get this:
Quote:
Fatal error: Maximum execution time of 30 seconds exceeded in /home/housemaa/public_html/db/test/sok.php on line 43

Name Phone Mobile Fax E-mail Website
line 43 is this: $fax=$row['fax'];
aog is offline
Reply With Quote
View Public Profile
 
Old 07-14-2004, 07:50 PM
Veter's Avatar
Super Talker

Posts: 136
What is on 43 line?
__________________
-= B2Netsolutions Inc. =-
-= Dedicated servers - Shoutcast hosting =-
Veter is offline
Reply With Quote
View Public Profile Visit Veter's homepage!
 
Old 07-14-2004, 07:53 PM
Veter's Avatar
Super Talker

Posts: 136
Ahh sorry

Get rid of that line

And remove all such lines
__________________
-= B2Netsolutions Inc. =-
-= Dedicated servers - Shoutcast hosting =-
Veter is offline
Reply With Quote
View Public Profile Visit Veter's homepage!
 
Old 07-14-2004, 08:00 PM
aog
Skilled Talker

Posts: 62
Location: Norway, Bergen
That helped

..but... take a look at this:
http://www.housemaadiah.com/db/test/sok.php
That is a search were I have entered the serach for Arne.
The 2 last outputs should not be there.. they don't exsicts in the database.
If you look at the "Delete" link, then you see it has link
http://www.housemaadiah.com/db/test/delete.php?id=.
All posts should have that link, but the post with id1 should have link http://www.housemaadiah.com/db/test/delete.php?id=1


EDIT:
Can I add some thing to $query="SELECT * FROM contacts WHERE first LIKE '%Arne%' ORDER BY first, last ASC"; saying that WHERE id LIKE $id
where $id = ( >= 1) or some thing like that?

Last edited by aog : 07-14-2004 at 08:09 PM.
aog is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to a smal page making script.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off