| | |
Newbie in need of help with some PHP code :)
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2009
Posts: 2
Reputation:
Solved Threads: 0
Hey! I'm quite new to this whole thing, so please don't fire me with shait on this one =D
I'm trying to learn PHP and MySQL, and atm I am trying to make a website which corresponds with a database - a database with customers.
1. I want the page to show all the customers in the database - with first- and surname.
2. I want each customer to be clickable - when you click a customer, it shows all the information about that customer which is stored in the database.
I can post some of the stuff I tried out with, but I'm not good with PHP (yet! =D), and therefore I got stuck quite early... but here's some of the stuff I've done so far..
This piece of code also gives me no spaces between the $customer_forename and $customer_surname.. How can I make a space between them?
And one last question
In this example, I have just created a link at the end of the customers listed - which says customer details.. Is there a way to make the $customer_forename and $customer_surname a clickable link which executes what I am trying to achieve?
Thanks, and sorry for not being really good at this, at all! =D
Have a nice day!
I'm trying to learn PHP and MySQL, and atm I am trying to make a website which corresponds with a database - a database with customers.
1. I want the page to show all the customers in the database - with first- and surname.
2. I want each customer to be clickable - when you click a customer, it shows all the information about that customer which is stored in the database.
I can post some of the stuff I tried out with, but I'm not good with PHP (yet! =D), and therefore I got stuck quite early... but here's some of the stuff I've done so far..
PHP Syntax (Toggle Plain Text)
<?php // Connect to the database server $dbcnx = @mysql_connect('localhost', 'root', 'password'); if (!$dbcnx) { exit('<p>Unable to connect to the database server at this time.</p>'); } // Select the database if (!@mysql_select_db('customerdb')) { exit('<p>Unable to locate the database at this time'); } ?> <p>Here are all the customers:</p><br /> // Request data from the database $customers = @mysql_query('SELECT * FROM customers'); if (!$customers) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); } while ($row = mysql_fetch_array($customers)) { $customerID = $row['kundeID']; $customer_forename = $row['forename']; $customer_surname = $row['surname']; echo '<p>' . $customer_forename . $customer_surname . ' <a href="' . $_SERVER['PHP_SELF'] . '?showcustomer=' . $customerID . '">' . 'customer details</a></p>'; } ?>
This piece of code also gives me no spaces between the $customer_forename and $customer_surname.. How can I make a space between them?
And one last question
In this example, I have just created a link at the end of the customers listed - which says customer details.. Is there a way to make the $customer_forename and $customer_surname a clickable link which executes what I am trying to achieve?Thanks, and sorry for not being really good at this, at all! =D
Have a nice day!
Last edited by hawkontvn; Nov 5th, 2009 at 2:33 pm.
•
•
Join Date: Feb 2008
Posts: 49
Reputation:
Solved Threads: 0
0
#2 Nov 5th, 2009
Hi there,
To get a space you could the html
That should sort that, as for making the name clickable replace 'customer details' in the link to .$customer_forname. " " .$customer_surname.
That should work in theory
Hope it helps
To get a space you could the html
PHP Syntax (Toggle Plain Text)
 
That should work in theory
Hope it helps
•
•
Join Date: Sep 2009
Posts: 26
Reputation:
Solved Threads: 2
1
#3 Nov 5th, 2009
You can do that above, but simply adding a quoted space should suffice as well:
Never use a hammer when a screwdriver will do.
PHP Syntax (Toggle Plain Text)
echo '<p>' . $customer_forename . " " . $customer_surname .
•
•
Join Date: Nov 2009
Posts: 2
Reputation:
Solved Threads: 0
Ok guys, thanks for the help so far! 
I should have known the   or the empty " " would work for the spacing... I also managed to make the names clickable..
But I still lack the tricky stuff :p
I made the names from the database clickable, but how can I make them show the rest of the data associated with the names show when I click a name?
Hope somebody can help out!

I should have known the   or the empty " " would work for the spacing... I also managed to make the names clickable..
But I still lack the tricky stuff :p
I made the names from the database clickable, but how can I make them show the rest of the data associated with the names show when I click a name?

Hope somebody can help out!
0
#5 Nov 5th, 2009
Also there is function called die() that will save you alot of coding.You have:
but you can do this:
See how simple it is :lol:
php Syntax (Toggle Plain Text)
# $dbcnx = @mysql_connect('localhost', 'root', 'password'); # if (!$dbcnx) { # exit('<p>Unable to connect to the database server at this time.</p>'); # }
but you can do this:
php Syntax (Toggle Plain Text)
$dbcnx = @mysql_connect('localhost', 'root', 'password') or die('<p>Unable to connect to the database server at this time.</p>');
0
#6 Nov 5th, 2009
0
#7 Nov 6th, 2009
ur link points to php self ie the same file. I suggest u to handle customer details retrieval from another php file.
anyway if u want to do that from the same file itself, u can have an if statement like
Hope this helps
anyway if u want to do that from the same file itself, u can have an if statement like
PHP Syntax (Toggle Plain Text)
if(isset($_REQUEST['showcustomer'])){ $query = 'SELECT * FROM customers where customerId = '.$_REQUEST['showcustomer']; $customerDetails = @mysql_query($query); //here is the data u need. Use it the way u want }
Hope this helps
•
•
•
•
Ok guys, thanks for the help so far!
I should have known the   or the empty " " would work for the spacing... I also managed to make the names clickable..
But I still lack the tricky stuff :p
I made the names from the database clickable, but how can I make them show the rest of the data associated with the names show when I click a name?
Hope somebody can help out!
Last edited by venkat0904; Nov 6th, 2009 at 2:15 am.
![]() |
Similar Threads
- help executing a .wav file with php code (PHP)
- Help newbie : need simple code (Python)
- I Need Help Please. Adding PHP Code To My Site. (PHP)
- How to test PHP code in offline in Linux + Apache 2 (PHP)
- PHP code not blending with HTML (PHP)
- My embedded php code won't execute (PHP)
Other Threads in the PHP Forum
- Previous Thread: mail() problem
- Next Thread: SMS gateway in php
Views: 258 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code codingproblem cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail memmory menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql static structure syntax system table tutorial up-to-date update updates upload url validation validator variable video web wordpress xml youtube






