My first query...

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

Post Reply
bertles86
Forum Newbie
Posts: 15
Joined: Wed Jan 26, 2011 3:20 pm

My first query...

Post by bertles86 »

Hi folks it's been a while since I've done PHP (years!) and I've written a connection script that works fine, now I'm calling that in a new script to do a simple select * into a table and it won't work!

Code: Select all

<?php 

	$page_title = 'View all clients';
	
	echo '<h1>View all clients</h1>';
	
	require_once ('../mysqli_connect.php');
	
	//Create Query
	
	$q = "SELECT * FROM client ORDER BY second_name ASC";
	
	//Run Query
	
	$r = @mysqli_query ($dbc, $q);
	
	if ($r) {
	
	//If it ran OK, display records
	
	echo  '<table align="center"
	cellspacing="3" cellpadding="3"
	width="75%">
	
	<tr>
		<td align="left"><b>Second Name</b></td>
		<td align="left"><b>First Name</b></td>
		<td align="left"><b>Invoice Address 1</b></td>
		<td align="left"><b>Invoice Address 2</b></td>
		<td align="left"><b>Invoice Address 3</b></td>
		<td align="left"><b>Town/City</b></td>
		<td align="left"><b>Postcode</b></td>
		<td align="left"><b>Primary Number</b></td>
		<td align="left"><b>Alt Number</b></td>
		<td align="left"><b>E-mail Address</b></td>
		<td align="left"><b>Company Name</b></td>
		<td align="left"><b>Notes</b></td>
		<td align="left"><b>First Contact</b></td>
	</tr>
	';
	
	//Fetch and print the records
	
	while ($row = mysqli_fetch_array($r,MYSQLI_ASSOC)) {
	echo '<tr>
	<td align="left">' $row['second_name'] . '</td>
	<td align="left">' $row['first_name'] . '</td>
	<td align="left">' $row['invoice_address_1'] . '</td>
	<td align="left">' $row['invoice_address_2'] . '</td>
	<td align="left">' $row['invoice_address_3'] . '</td>
	<td align="left">' $row['invoice_town_city,'] . '</td>
	<td align="left">' $row['invoice_postcode'] . '</td>
	<td align="left">' $row['primary_number'] . '</td>
	<td align="left">' $row['alt_number'] . '</td>
	<td align="left">' $row['email'] . '</td>
	<td align="left">' $row['company_name'] . '</td>
	<td align="left">' $row['notes'] . '</td>
	<td align="left">' $row['contact_date'] . '</td>
	</tr>';
	
	}
	
	echo '</table>'; //Close table
	
	mysqli_free_result ($r); //Free resources
	
	} else {
	
	echo '<p class="error">The data could not be found, sorry.</p>';
	
	echo '<p>' . mysqli_error($dbc) . '<br/><br />Query: ' . $q . '</p>';
	
	} ($r) IF.
	
	
	mysqli_close($dbc); //Close database
	
?>
Any help on this error?
Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in C:\wamp\www\view_clients.php on line 46
Thanks in advance!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: My first query...

Post by AbraCadaver »

All the lines that look like this:

Code: Select all

<td align="left">' $row['second_name'] . '</td>
Are missing a . before the $row var.

Also, what is this???

Code: Select all

} ($r) IF.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
bertles86
Forum Newbie
Posts: 15
Joined: Wed Jan 26, 2011 3:20 pm

Re: My first query...

Post by bertles86 »

Cheers, works a treat now.

I can format it a bit better using the html correcto? Like column widths etc?
gooney0
Forum Commoner
Posts: 56
Joined: Fri Jan 21, 2011 1:40 pm
Location: Reston, VA

Re: My first query...

Post by gooney0 »

Sure you can add all the HTML you want.

While you're brushing up I'd recommend getting into CSS. That way you could more easily reuse your PHP code and just change the stylesheet.

Setting attributes in HTML still works, but is a bit out of style.
Post Reply