Current location: Hot Scripts Forums » Programming Languages » PHP » Learning PHP & MySQL


Learning PHP & MySQL

Reply
  #1 (permalink)  
Old 05-11-04, 12:32 PM
eq1987 eq1987 is offline
Wannabe Coder
 
Join Date: Dec 2003
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
Learning PHP & MySQL

I have read some basic tutorials, but i would like to learn more about PHP and MySQL working together. Might anyone know of some good *online* tutorials I could work with? I want to try to build a search. The search would go through a MySQL DB and find "items". Thanks
Reply With Quote
  #2 (permalink)  
Old 05-11-04, 03:20 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
after you've got the basics, head to http://www.php.net/manual/en/
and look there and search ..
the step that will make you a good programmer is to "try, think and try" -Blaw you have to start writing some simple scripts, and you will struggle at the begining but you will get it at last !
if I were you, I wouldn't try making search engines first! because they are not easy! and you may hate programming when you can't get the results you are expecting!
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 05-11-04, 04:04 PM
eq1987 eq1987 is offline
Wannabe Coder
 
Join Date: Dec 2003
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
I have another question. I have constructed how i believe my search will result. Could read how i want it to *work*, and tell me if PHP and MySQL will function correctly to do this.

It would be built on three files. One is the search.php, to display the names of the items that have relevancy. Second is PHP to display the item. Third is to easily submit information into the MySQL DB. I know this code isnt PHP, its just enough for you to understand what i want. (LOTS of missing signs)
search.php
<?php
db connect
SELECT item_name FROM item WHERE item_name LIKE '%user_input%' ORDER BY item_name;
$items = result
SELECT item_name FROM item WHERE item_url LIKE '$items' ORDER BY item_name;
$url = result
SELECT item_name FROM item WHERE item_url LIKE '$items' ORDER BY item_name;
$stats = result

echo = $url;
echo = $items;
echo = $stats;

?>
Stats is information about the item. I would hopefully design it into a array, but thats later.

submit.php
<?php

$wisdom = textbox that submits a # into the table as "wisdom"
so forth till all my stats are done..
?>

select.php

<?php
include search.php

echo = $name
echo = $array/fuction with stats
echo = all the other good stuff
?>

I hope you understand how i want it structured? How i did it, would that be possible? Thanks
Reply With Quote
  #4 (permalink)  
Old 05-11-04, 08:47 PM
nekeno12 nekeno12 is offline
Wannabe Coder
 
Join Date: May 2004
Location: CO
Posts: 214
Thanks: 0
Thanked 0 Times in 0 Posts
You've got some syntax errors in your php. YOU CAN'T USE %VARIABLE% in PHP. That's ASP syntax.
Let me help you correct them. You code should look like this:

PHP Code:

<?php 


// you've got to connect to MySQL first
$connect = @mysql_connect("localhost""username""password") or die("could not connect to server");

// then select the database you want to work with

$db_select = @mysql_select_db("dbname") or die("could not select the database");

// then execute your query.  there's no need for three queries when you get an array result
$SQL "SELECT * FROM item WHERE item_name = '$user_input'";

$result = @mysql_query($SQL) or die("Could not run query");

$row mysql_fetch_array($result);

echo(
"$row[url]");
echo(
"$row[item]");
echo(
"$row[stats]");


?>
This should help with the array side

I don't have time to help with submit.php and select.php. But this code should help a lot.
Reply With Quote
  #5 (permalink)  
Old 05-11-04, 10:14 PM
nekeno12 nekeno12 is offline
Wannabe Coder
 
Join Date: May 2004
Location: CO
Posts: 214
Thanks: 0
Thanked 0 Times in 0 Posts
BTW

You may want to check out php.net to check syntax corrections.

Just type http://www.php.net/(functionhere)

Like http://www.php.net/mysql_connect

or http://www.php.net/echo

And you'll get the description of each function.
Reply With Quote
  #6 (permalink)  
Old 05-12-04, 05:46 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
Quote:
You've got some syntax errors in your php.
just note what he wrote:
Quote:
I know this code isnt PHP, its just enough for you to understand what i want. (LOTS of missing signs)
this is what is called psedue coding !
where you just type the script in an understandable way ..

Quote:
YOU CAN'T USE %VARIABLE% in PHP. That's ASP syntax.
he wasn't using it in PHP!! he was using it in SQL query which is the right way to do simple searching in tables ..
and this sign (%) is a wildcard in SQL..
using equal mark (=) in search is not effecient at all !!
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #7 (permalink)  
Old 05-12-04, 12:34 PM
eq1987 eq1987 is offline
Wannabe Coder
 
Join Date: Dec 2003
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
So will that code above work? I cant try ATM, my DB isnt working. Also, how could i display like 20 results a page and have a next page? or is that really hard heh?
Reply With Quote
  #8 (permalink)  
Old 05-12-04, 02:39 PM
eq1987 eq1987 is offline
Wannabe Coder
 
Join Date: Dec 2003
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
Ive used that code, edited some of course, works fine. But its case sensitive. Is it easy to change that? i want it so, if someone searches php or PHP, PhP proGraMMing might come up. Any help is appreciated. Thanks!
Reply With Quote
  #9 (permalink)  
Old 05-12-04, 06:14 PM
eq1987 eq1987 is offline
Wannabe Coder
 
Join Date: Dec 2003
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
Yet another post. Can anyone tell me why this code wont put info into my DB?

<form method="post" action="<?php echo $PHP_SELF?>">

Item Name:<input type="Text" name="name"><br>
URL:<input type="Text" name="url"><br>
Picuture URL:<input type="Text" name="picurl"><br>
Strength:<input type="Text" name="str"><br>
Stamina:<input type="Text" name="sta"><br>
Dexterity:<input type="Text" name="dex"><br>
Agility:<input type="Text" name="agi"><br>
Wisdom:<input type="Text" name="wis"><br>
Intelligance:<input type="Text" name="int"><br>
Charisma:<input type="Text" name="cha"><br>
Effect 1:<input type="Text" name="effone"><br>
Effect 2:<input type="Text" name="efftwo"><br>
Effect 3:<input type="Text" name="effthree"><br>
<input type="Submit" name="submit" value="Enter information">

</form>
<?php



if ($submit) {

// process form

$db = mysql_connect("localhost", "login", "pass");

mysql_select_db("dbasdf",$db);

$sql = "INSERT INTO itemsearch (name,url,picurl,str,sta,dex,agi,wis,int,cha,effon e,efftwo,effthree) VALUES ('$name','$url','$picurl','$str','$sta','$dex','$a gi','$wis','$int','$cha','$effone','$efftwo','$eff three')";

$result = mysql_query($sql);

echo "Information entered.\n";

} else{



// display form



?>

<?php



} // end if



?>
Reply With Quote
  #10 (permalink)  
Old 05-14-04, 11:50 AM
eq1987 eq1987 is offline
Wannabe Coder
 
Join Date: Dec 2003
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
Anyone know? Also, might anyone tell me how i can display multiple "items" per page? not just 1? Do i use a loop type of command?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
PHP, MySQL, WML superman PHP 0 03-04-04 10:46 AM
question about updating a page or database for an, php and mysql updating mikewooten PHP 1 02-12-04 12:11 AM
Generating PHP code for MySQL ptesone General Advertisements 1 02-03-04 08:26 AM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 06:02 AM


All times are GMT -5. The time now is 10:32 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.