Page 1 of 1

My first query...

Posted: Wed Jan 26, 2011 3:23 pm
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!

Re: My first query...

Posted: Wed Jan 26, 2011 3:30 pm
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.

Re: My first query...

Posted: Thu Jan 27, 2011 4:17 am
by bertles86
Cheers, works a treat now.

I can format it a bit better using the html correcto? Like column widths etc?

Re: My first query...

Posted: Thu Jan 27, 2011 3:29 pm
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.