mpc123 15 Junior Poster in Training

Hi I am trying to join tables and fields and one of the tables had fields like field.field . So when I try to do a join it does not know the table field name as you end up with something like Table1.field.Name

How do I get round this please

$result = mysql_query("SELECT DISTINCT `Table1.field.Name`, `Table1.field.Name1`, `Table1.field.Name2`, `Table1.field.Name3`, `Table2.fieldName1`, `Table2.fieldName1` FROM Table1, Table2 WHERE `Table1.field.Name` = '$txt1' and `Table1.field.Name1` = '$txt2' and Table1.field.name2 = table2.fieldname1") or trigger_error(mysql_error().$sql);
mpc123 15 Junior Poster in Training

OK thanks, how would I change it so I do have a value please

mpc123 15 Junior Poster in Training

Hi

I have been struggling with this for a while and cant find the answer, the code below shows my else if statement everything goes fine until using the else if statement and ' . $img . ' ends up being blank.

It should be if field 4 is 0.00 then ' . $img . ' should be nothing
else if field 4 is blank then ' . $img . ' should be nothing
else there is something in field 4 then ' . $img . ' should be <img src="/images/' . ($row['field4']) . '.jpg" height ="60" border="0" ALIGN="Left" />

All 3 come up with no code at all in the place where ' . $img . ' should be

Please help

$result = mysql_query("SELECT DISTINCT `field1`, `field2`, `field3`, `field4` FROM TABLE WHERE `field1` = '$txt1' and `field2` = '$txt2'") or trigger_error(mysql_error().$sql);
while($row = mysql_fetch_array($result)){


                                if($row['field4'] == 0.00)
                        {
                            $img = '';
                        }
                        else
                        {
                            if($row['field4'] ='')
                            {

                                $img = '';

                            }
                            else
                            {

                                $osimg = '<img src="../'. $row['field4'].'" height ="150" border="0" ALIGN="Left" />';

                            }
                        }

echo '
                                  <img src="../'. $row['field3'].'" height ="150" border="0" ALIGN="Left" alt="'. $row['field1'].' '. $row['field2'].'" />' . $img . '';
}

?>
mpc123 15 Junior Poster in Training

Its ok thanks for your help I sorted the decimal point thing

for anyone else

'.sprintf("%.2f",$total).'

mpc123 15 Junior Poster in Training

brilliant that owkrs perfect. Now only problem is i need 2 decimal points not 10 please :)

Thanks

mpc123 15 Junior Poster in Training

HI thanks for your reply , where would I put that please as i already have a query for my table

Thanks

mpc123 15 Junior Poster in Training

All the code is very large so I will go over what I am doing

resource is in the head
$result = ( $row['field3'] - ($row['field1'] / $row['field2']) );

i am echoing a table out with all the info in with a query and while($row = mysql_fetch_array($result))

with loads of rows, and one of those rows is your code

echo '<td>'.$result.'</td>';

Hope this is ok for the info

mpc123 15 Junior Poster in Training

I have now fixed that with a @ before the brackets

Now I get the error of resource id# where the result should echo.

Can you help?

mpc123 15 Junior Poster in Training

HI Thanks for the help but the error comes up as Warning: Division by zero

mpc123 15 Junior Poster in Training

Hi

I have to echo out some fields but "field 1" "field 2" "field 3" has a numeric value.

I need to divide field 1 by field 2 and then take that result off of field 3 and echo that result.

The code is part of a table this is the code for that row

Hope someone can help

 echo '<td>' . $row['field3'] . '</td>';
mpc123 15 Junior Poster in Training

HI I managed to sort it by using arrays with the string replace
For anyone else who would need it

$old = array(' ', '&pound;');
$new = array('-', '£');

$newfile = ''. $file['whatever'].'/'. $file['whatever'].'-'. str_replace($old,$new,trim($file['nightmare'])) . '.php';

mpc123 15 Junior Poster in Training

Hi, firstly thanks for offering help. Basically i need to know how to do 2x string replace on the nightmare file, currently I have one in at the moment replacing space with a dash but how would I do 2 replaces please

Thanks

mpc123 15 Junior Poster in Training

Hi

I am creating some files of which are taken from database fields, the problem is the field in the database has &pound; in which is great as it is needed when in the browser page. The problem I have is when making the file is that it creates the newfile name as &pound; in the url rather than £. How do i replace PART of the field ['nightmare'] to make £ rather than $pound; please.

The line with the problem is

$newfile = ''. $file['whatever'].'/'. $file['whatever'].'-'. str_replace(' ','-',trim($file['nightmare'])) . '.php';

Thanks for any help

mpc123 15 Junior Poster in Training

thanks for the reply and sorry to sound totally thick but where / how would I use it?

mpc123 15 Junior Poster in Training

Hi hope you can help with this.

Fields have spaces in the fields being echoed, how would I use the replace to change those spaces to a dash.

'Make' field will be something like blar blar blar and I need it to be blar-blar-blar

<h4><a href="">'. $row['Make'].'</a></h4>
Hope you can help. Thanks

mpc123 15 Junior Poster in Training

Hi Sorry, now i have a problem with this, if you can help please

fields have spaces in the fields being echoed, how would I use the replace to change those spaces to a dash.

Make field will be something like blar blar blar and I need it to be blar-blar-blar

<h4><a href="">'. $row['Make'].'</a></h4>

Hope you can help again. Thanks

mpc123 15 Junior Poster in Training

thanks for both of your help, Its now works :)

mpc123 15 Junior Poster in Training

Hi

I am trying to echo this info with the different rows in the database but when I try the following code only the first result shows up. Please can someone help

<?php
$con = mysql_connect("localhost","blar","blar");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("blar", $con);

$result = mysql_query("SELECT * FROM TABLE") or trigger_error(mysql_error().$sql);
$row = mysql_fetch_array($result); {
echo '<ul class="feature-list-smaller">
            <li>
                <a href="#" class="icon"><img src="image.png" width="52" height="52" alt="" /></a>
                <div class="text">
                    <h4><a href="'. $row['Link'].'-contract.php">'. $row['Make'].' '. $row['Model'].'</a></h4>
                </div>
            </li>
            </ul>';
}
echo "/n";
?>

Hope someone can help. Thanks in advance

mpc123 15 Junior Poster in Training

IT works perfectly now :)
Thank you so much fo your help

mpc123 15 Junior Poster in Training
<?php
$con = mysql_connect("localhost","blar","blar");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("blar", $con);
$m = $_GET['m'];
ob_start();
$query = "SELECT `ID`, 'Link' FROM TABLE where `ID` ='$m' LIMIT 1"; 
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
if ($m == "$row['ID']"){$link = "$row['Link']";}
   echo "sending you to new page";
header("Location: $link");
ob_flush();
?>
mpc123 15 Junior Poster in Training

Hi

Thanks for you quick reply, I have added that line and added the $row yet I get this error
unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

Can you help?

mpc123 15 Junior Poster in Training

Hi

Im having a go at this, but not good on the php thing, thats why im hoping you can help.

I am trying to set up a jump script from one I have used for 1 or 2 urls, now I have a database of around 500000 lines, each one has an id field and a link field to jump to. I can send the info for the function but cant get it to add the field from the database. This is the code I have got so far.

<?php
$con = mysql_connect("localhost","blar","blar");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("blar", $con);
$m = $_GET['m'];
ob_start();
$query = "SELECT `ID`, 'Link' FROM TABLE where `ID` ='$m' LIMIT 1"; 
$result = mysql_query($query) or die(mysql_error());
if ($m == "['ID']"){$link = "['Link']";}
   echo "sending to page now";
header("Location: $link");
ob_flush();
die();
?>

the page is sending the m=id and the page "sending to page now comes" up but no redirect occurs?
Hope someone can help
Thanks in advance

mpc123 15 Junior Poster in Training

Right i have now decided to put the rows into a table in database and run from that.

I have got a fetch array with a loop setting and have now got the result on a webpage all the details i require which is great. over 400 results in about 2 seconds :) just what i wanted.

An html page is not really what i require though so if somebody can help, how i then get the contents of this into a txt file rather than html.

The reason html wont do is because im using the data then to import somewhere else of which needs to be a utf-8 txt file.

Hope you understand what i mean and hope you can help
Thanks in advance

mpc123 15 Junior Poster in Training

Hi

If somebody can point me in the right direction for what i require that would be great.
I will give an example rather than exactly what i require just to make it simplier to get the information across

1.I have a csv file which has around 400 rows in it with just one colomn eg names (with all different names in each row

2.I have a set sentence eg
my name is $name and i like being called $name and there is nothing i would more like to be called than $name


I would like to replace the $name in the sentence with the names in the csv file and repeat for each one, then print this to make a txt file for an import process

not only this but each row that prints is to be numbered starting from a number of my choice each time


Hope somebody can help please
Thanks in advance

mpc123 15 Junior Poster in Training

any links to help would be great

mpc123 15 Junior Poster in Training

thanks for your reply, i will try and serach for that information you have given me

mpc123 15 Junior Poster in Training

Hi

I have

1.database already set up with around 5000 products with all fields required.

2. create a page template with query code and code to echo out the results of the fields of a product.

I now need to know how to make each product from the database produce a page based upon what i already have.

Please can someone help as i have been searching the net for hours to try and find something to help

Thanks in advance

mpc123 15 Junior Poster in Training

OK THANKS, how do i get that in with what i already have?

mpc123 15 Junior Poster in Training

Hi i have a form which also uses php to insert records into database, just name and address but also need them to pay via paypal, please help

Form code

<form action="insert.php" method="post">
  <div align="center">Firstname: 
    <input type="text" name="firstname" />
    Lastname: 
  <input type="text" name="lastname" />
    Email: 
  <input type="text" name="email" />
  <input type="submit" />
  </div>
</form> 
<div align="center">

insert.php code

<?php
$con = mysql_connect("x","x","x");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("databasename", $con);

$sql="INSERT INTO Persons (FirstName, LastName, Email)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[email]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

$to = "mymail"; //Your email address
$subject = " Paying member"; //Email subject
$message = "new details have been entered into the database"; //Body of email
mail($to, $subject, $message);
	  
echo "Thank you you will recieve information shortly";

mysql_close($con)
?>

thanks

mpc123 15 Junior Poster in Training

Im trying to get the queries and results to load quicker. I have 10 of these after each other with slightly different queries, how can i optimize this please, i have tried removing select * and entering the field names require (which is about 9 rather than the 40 with * but it still is very slow).

<?php
$con;
$result = mysql_query("SELECT * FROM table WHERE `Field.1` = '$test' and `Field.2` > $test1 ORDER BY `Field.3` + 0 LIMIT 3") 
or die(mysql_error());  
 
echo "<table class = sample >";
echo "<tr> <th>h1</th> <th>h2</th> <th>h3</th> <th>h4</th> <th>h5</th> <th>h6</th> <th>h7</th></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
	echo "<tr><td>";
	echo $row['h1'];
	echo "</td><td>";
        echo $row['h2'];
	echo "</td><td>"; 
	echo $row['h3'];
	echo "</td><td>";
	echo $row['h3'];
	echo "</td><td>";
	echo $row['h4'];
	echo "</td><td>";
	echo $row['h5'];
	echo "</td><td>";
	echo $row['h6'];
	echo "</td><td>";
	echo $row['h7'];
	echo "</td><tr>";
} 
 
echo "</table>";
?>
mpc123 15 Junior Poster in Training

that really does help thank you very much

mpc123 15 Junior Poster in Training

can anybody help with this?

mpc123 15 Junior Poster in Training

I have a very large table and would need to split into lots of tables.

The large table has lots of fields of which `Model.ID` gives a number of the product and this is repeated lots of times with other fields used in the row.

I need to create lots of new tables based on the Model ID field and its associated fields in that row need to be kept together. So if `Model.ID` = 1614 then a new table will be created and inserted into that will be all the rows that have that.

Obviously i need code that does them all and the `model.ID` dont go in order and are pretty random.


Could anybody help please, as this is way above what i can do php wise.

mpc123 15 Junior Poster in Training

Yeah i could split it up but i have to download the updates once per week ,so presume would have to get some script to split in up in some kind of order and then rewrite the web side to go from the different databases, which sounds a big job to me. How would i convert that in to 1 array before i try spliting the databases

Thanks for your reply

mpc123 15 Junior Poster in Training

I have a database which is quite large (around 1.7 million rows, with about 40 fields) . I want to do about 10 different queries and echo these results out in a tables that are spaced with headings for the seperate results, but i am worried about the length of time it will take to show these.

How would I make these 10 queries give a result faster than using the example code 10 times below each other with slightly different field names.

An example of 1 of the queries is below, all queries come from the same database and table just slightly different fields.

How would I make these 10 queries give faster results.

<?php
$con;
$result = mysql_query("SELECT * FROM table WHERE `Field.1` = '$test' and `Field.2` > $test1 ORDER BY `Field.3` + 0 LIMIT 3") 
or die(mysql_error());  

echo "<table class = sample >";
echo "<tr> <th>h1</th> <th>h2</th> <th>h3</th> <th>h4</th> <th>h5</th> <th>h6</th> <th>h7</th></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
	echo "<tr><td>";
	echo $row['h1'];
	echo "</td><td>";
        echo $row['h2'];
	echo "</td><td>"; 
	echo $row['h3'];
	echo "</td><td>";
	echo $row['h3'];
	echo "</td><td>";
	echo $row['h4'];
	echo "</td><td>";
	echo $row['h5'];
	echo "</td><td>";
	echo $row['h6'];
	echo "</td><td>";
	echo $row['h7'];
	echo "</td><tr>";
} 

echo "</table>";
?>
mpc123 15 Junior Poster in Training

HI my code has an error of -

Unexpected character in input: ' in url/database.php on line 9
Parse error: syntax error, unexpected T_STRING in url/database.php on line 9

line 9 is $result = mysql_query($sql) or die(mysql_error());

Can anybody tell me what the problem is please

<?php
require_once 'config.php';

$dbConn = mysql_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error());
mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error());

function dbQuery($sql)
{
	$result = mysql_query($sql) or die(mysql_error());
	
	return $result;
}

function dbAffectedRows()
{
	global $dbConn;
	
	return mysql_affected_rows($dbConn);
}

function dbFetchArray($result, $resultType = MYSQL_NUM) {
	return mysql_fetch_array($result, $resultType);
}

function dbFetchAssoc($result)
{
	return mysql_fetch_assoc($result);
}

function dbFetchRow($result) 
{
	return mysql_fetch_row($result);
}

function dbFreeResult($result)
{
	return mysql_free_result($result);
}

function dbNumRows($result)
{
	return mysql_num_rows($result);
}

function dbSelect($dbName)
{
	return mysql_select_db($dbName);
}

function dbInsertId()
{
	return mysql_insert_id();
}
?>
mpc123 15 Junior Poster in Training

Im looking email members from a database where the emails are stored but also in a seperate table would be the information I want to send to them . I have this code of which i could use manually but

1. how do i get the multiple recipients to go in automatically rather than manually.
2. subject and message of the email from another table

Would be nice if you could help.

<?php
// multiple recipients
$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>
mpc123 15 Junior Poster in Training

perfect thank you

mpc123 15 Junior Poster in Training

I have this very easy form to store info in a database table but i would like to be emailed once somebody has entered the details, how would i do this please?

Form

<form action="insert.php" method="post">
  <div align="center">Firstname: 
    <input type="text" name="firstname" />
    Lastname: 
  <input type="text" name="lastname" />
    Email: 
  <input type="text" name="email" />
  <input type="submit" />
  </div>
</form>

Insert.php

<?php
$con = mysql_connect("x","x","x");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("x", $con);

$sql="INSERT INTO Persons (FirstName, LastName, Email)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[email]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "Thank you you will recieve information shortly";

mysql_close($con)
?>
mpc123 15 Junior Poster in Training

Firstly thanks for your reply.

I would prefer say 20 words and the formatting is all in paragraphs eg html <p> </p>

mpc123 15 Junior Poster in Training

I have a news feature on a website and have a page that shows all of the news and a link to the actual page of each individual news. On first page that lists all the news i would like to limit the amount of Characters that is echoed from the database field. So from the code below where it states

echo $row;

that is where i need to limit the amount of characters

if you could help that would be great.

<?php
mysql_connect("","","");
mysql_select_db("");
$result = mysql_query("SELECT * FROM news ORDER BY id desc") 
or die(mysql_error());  

echo "<table class = feature >";
echo "<tr> <th></th> <th></th> <th></th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
	echo "<tr><td>";
	echo $row['Date'];
	echo "</td><td>";
	echo "<a href='".$row['Link']."'>".$row['Title']."</a>";
	echo "</td><td>";	 
    echo $row['News'];
	echo "</td></tr>";
} 
echo "</table>";
?>
mpc123 15 Junior Poster in Training

Also how would i do this by date also, eg if i only want to show the total profit between 2 certain dates what the code be?

There is a date field in the database.

mpc123 15 Junior Poster in Training

thanks for your help , it now works. Thanks also for the advice. I will mark as solved

mpc123 15 Junior Poster in Training

sorry copied totally the wrong thing, i have this code

connx +

$query = "SELECT SUM(Profit) FROM table";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
	echo "Total ". $row['SUM(profit)'];
}
?>

I get the word total on the html page but no actaul figure total of the sum, can somebody help please

mpc123 15 Junior Poster in Training

Hi im looking to echo a result of a query code i have at the moment is connections +

<?php
$result = mysql_query("SELECT SUM(tablefield) FROM table") 
or die(mysql_error());

got no idea if this is right, i seem to have got really mixed up with this.

Can anybody help please

mpc123 15 Junior Poster in Training

thanks it worked perfect and now i understand how that works, probably not difficult to you but just learning. I will mark as solved

mpc123 15 Junior Poster in Training

Hi , hope you can help i have this code

<?php
mysql_connect("localhost","x","x");
mysql_select_db("x");
$result = mysql_query("SELECT * FROM x") 
or die(mysql_error());  

echo "<table class = feature >";
echo "<tr> <th></th> <th></th> <th></th> </tr>";

while($row = mysql_fetch_array( $result )) {
	
	echo "<tr><td>";
	echo $row['Date'];
	echo "</td><td>";
	echo $row['Title'];
	echo "</td><td>";	 
    echo $row['News'];
	echo "</td></tr>";
} 
echo "</table>";
?> <p>

of which everything is filled in correctly but i now have a field in the database called link, i want the Title row text to link to the link field in the database.

Hope you can help

Thanks in advance

mpc123 15 Junior Poster in Training

sorry my fault a typo in the car i put cart.

Thank you very much i will post as solved

mpc123 15 Junior Poster in Training

thanks but this shows a blank image as the image url shows images/.jpg , so it is not echoing the database field into the image url.

Can you help please

mpc123 15 Junior Poster in Training

no that shows on the webpage

bmw x5images/bmw x5

can anyone still help?