Jump to content

Is This The Right Way?


ChompGator

Recommended Posts

Hey,

 

What I want to do is list all my users email address from the database, but separate them by a semi colon, is this the right way to do this? I didn't add in the scripting to separate them all by a semi colon, because I wasn't sure what the script was to do that?

 

<?php
$con = mysql_connect("****","****","****") or die('Could not connect: ' . mysql_error());
mysql_select_db("login", $con);

$result = mysql_query("SELECT * FROM subscribe");

echo "<table border='1'>
<th>Email</th>
</tr>";while($row = mysql_fetch_array($result))
  {
  echo "<td>" . $row['email'] . "</td>";
  }
echo "</table>";mysql_close($con);
?> 

Link to comment
Share on other sites

Updated, I changed the script to whats below, but Im getting a parse error on line 8 unepected '}'  Any suggestions on how to fix it

 

<?php
$con = mysql_connect("***","****","*****") or die('Could not connect: ' . mysql_error());
mysql_select_db("login", $con);

$result = mysql_query("SELECT * FROM subscribe");
while($row = mysql_fetch_assoc($result)){
$row['email']
}
?>

Link to comment
Share on other sites

I added the semi-colon after where you said too, now Im getting this error,

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\hosting\member\aiim\affiliates\email.php on line 6

 

here is what the script looks like now

 

<?php
$con = mysql_connect("****","***","****") or die('Could not connect: ' . mysql_error());
mysql_select_db("subscribe", $con);

$result = mysql_query("SELECT * FROM subscribe");
while($row = mysql_fetch_assoc($result)){
$row['email'];
}
?>

Link to comment
Share on other sites

I added the semi-colon after where you said too, now Im getting this error,

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\hosting\member\aiim\affiliates\email.php on line 6

 

here is what the script looks like now

 

<?php
$con = mysql_connect("****","***","****") or die('Could not connect: ' . mysql_error());
mysql_select_db("subscribe", $con);

$result = mysql_query("SELECT * FROM subscribe");
while($row = mysql_fetch_assoc($result)){
$row['email'];
}
?>

 

echo $row['email'];

Link to comment
Share on other sites

Still the error on

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\hosting\member\aiim\affiliates\email.php on line 6

 

Here is the script now:

<?php
$con = mysql_connect("mysql105.mysite4now.com","aiim","k7YuHeFv") or die('Could not connect: ' . mysql_error());
mysql_select_db("subscribe", $con);

$result = mysql_query("SELECT * FROM subscribe");
while($row = mysql_fetch_assoc($result)){
$row['email'];
}
?>

 

Link to comment
Share on other sites

when ever i done the echo $row['email']; i giving u a hint on what u missed out copy thry this code below

 

<?php

$con = mysql_connect("******","*****","*****") or die('Could not connect: ' . mysql_error());
mysql_select_db("*****", $con);

$result = mysql_query("SELECT * FROM subscribe");
//make sure you have data to show
$getdata = mysql_num_rows($result);

if($getdata == 0) {
echo 'No information to show';
} else {

while($row = mysql_fetch_assoc($result)){
echo $row['email'];//to print the results and show the information
}

}
?>

 

also if this still comes up with an error change mysql_fetch_assoc to mysql_fetch_array some times that can have an affect

Link to comment
Share on other sites

Tried that out and got this error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\hosting\member\aiim\affiliates\email.php on line 7

 

So I altered the code to what you see below, its not displaying errors anymore, its just displaying a blank white page, does anyone know why that is:

 

<?php 
$con = mysql_connect("**","**","***") or die('Could not connect: ' . mysql_error()); 
mysql_select_db("login", $con); 

$result = mysql_query("SELECT * FROM subscribe"); 

if ($r = mysql_query ($result)) { 
while ($row = mysql_fetch_array ($r)) { 
echo $row['email']; 
} 
} 
?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.