[PHP] ASP to PHP language problems

2004-03-10 Thread Alistair Hayward
Hi ,

What is the equavilant in PHP to creating a recordset in ASP using a query?
This is what I do in PHP:
..
dim Type
Type = CStr(Request.QueryString("action")) (getting parameter from URL)
Dim cnn  ' ADO connection
Dim rst  ' ADO recordset
Dim strDBPath  ' path to my Access database (*.mdb) file
strDBPath = Server.MapPath("/_database/database.mdb")
Set cnn = Server.CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
Set rst = cnn.Execute("SELECT * FROM table WHERE Type ='" & type & "' 
order by style")
..
I can then call any field and display it in the html by using :
<%=rst.fields("whatever").value%>
..
I can also create a loop:
<%Do While Not rstSimple.EOF%>
do something
<%
rstSimple.MoveNext
Loop
%>


Please can someone show me how to do the same thing in PHP?

Alistair

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: ASP to PHP language problems

2004-03-10 Thread Alistair Hayward
This is what I get when I try to create the recordset

Notice: Use of undefined constant DBlink - assumed 'DBlink' in 
D:\Development\Completed\Sealhouse\phpSealTest\ProductSpecs.php on line 24

Warning: mysql_query(): supplied argument is not a valid MySQL-Link 
resource in 
D:\Development\Completed\Sealhouse\phpSealTest\ProductSpecs.php on line 24

Ligaya Turmelle wrote:

I don't know ASP but I think this is what you want:

$sql = "SELECT * FROM table WHERE Type = \"& type & \"  order by style;";

$resultID = mysql_query($sql, DBlink);  // send the query and returns a
pointer to the results
while ($row = mysql_fetch_assoc($resultID))   // while there are results
give them to me as an associative array
   //
results could also be returned as an array, object, or row
   //
see mysql_fetch_array, mysql_fetch_object, and mysql_fetch_row respectively
{
   Here is a loop
}
"Alistair Hayward" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hi ,

What is the equavilant in PHP to creating a recordset in ASP using a
query?

This is what I do in PHP:
..
dim Type
Type = CStr(Request.QueryString("action")) (getting parameter from URL)
Dim cnn  ' ADO connection
Dim rst  ' ADO recordset
Dim strDBPath  ' path to my Access database (*.mdb) file
strDBPath = Server.MapPath("/_database/database.mdb")
Set cnn = Server.CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
Set rst = cnn.Execute("SELECT * FROM table WHERE Type ='" & type & "'
order by style")
..
I can then call any field and display it in the html by using :
<%=rst.fields("whatever").value%>
..
I can also create a loop:
<%Do While Not rstSimple.EOF%>
do something
<%
rstSimple.MoveNext
Loop
%>

Please can someone show me how to do the same thing in PHP?

Alistair
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: ASP to PHP language problems

2004-03-10 Thread Alistair Hayward
Thanks Chris,

Believe me, I have been doing research non-stop for a few days now and 
this is my last resort.
The problem is the language. I can't find what I'm looking for on the 
net because I don't know what it's called.

I have worked out how to create a connection to a mySQL server and 
database. (after spending so much time configuring and installing PHP 
and mySQL for the first time)
I now know how to use include files.
I can not figure out how to create a recordset and call fields from the 
record set while performing a loop.

I have done heaps of research, but have not found what I need.

Chris W. Parker wrote:

Alistair Hayward <mailto:[EMAIL PROTECTED]>
on Wednesday, March 10, 2004 2:46 PM said:

This is what I get when I try to create the recordset

Notice: Use of undefined constant DBlink - assumed 'DBlink' in
D:\Development\Completed\Sealhouse\phpSealTest\ProductSpecs.php on
line 24


well you're going to need to do a *little* research on your own.

oh what the heck...

DBlink is the same as your cnn in your asp code. in other words you
still need to create a connection to a database.


chris.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: ASP to PHP language problems

2004-03-10 Thread Alistair Hayward
This is what I have:

$connection = mysql_connect("localhost","root","batman");
if (!$connection) {
echo "Couldn't make a connection!";
exit;
}
$db = mysql_select_db("sealhouse", $connection);
if (!$db) {
echo "Couldn't select database!";
exit;
}
$type = $_GET['type'];
$sql = "SELECT * FROM tbCategory WHERE Type =$type order by style";
    $resultID = mysql_query($sql, DB);

?>
Chris W. Parker wrote:

Alistair Hayward <mailto:[EMAIL PROTECTED]>
on Wednesday, March 10, 2004 2:46 PM said:

This is what I get when I try to create the recordset

Notice: Use of undefined constant DBlink - assumed 'DBlink' in
D:\Development\Completed\Sealhouse\phpSealTest\ProductSpecs.php on
line 24


well you're going to need to do a *little* research on your own.

oh what the heck...

DBlink is the same as your cnn in your asp code. in other words you
still need to create a connection to a database.


chris.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] ASP to PHP language problems

2004-03-10 Thread Alistair Hayward
Richard:
Thank you so much!
Richard Davey wrote:

Hello Alistair,

Wednesday, March 10, 2004, 10:26:03 PM, you wrote:

AH> dim Type
AH> Type = CStr(Request.QueryString("action")) (getting parameter from URL)
unset($type);
$type = $_GET['action'];
(Please note - you don't HAVE to "unset" each variable, but if you are
working in a Register Globals ON environment, it's a good safety
measure).
AH> strDBPath = Server.MapPath("/_database/database.mdb")

MySQL doesn't work the same way as MDB files (thank goodness), so you
need to create a connection to the MySQL database:
$link = mysql_connect('localhost', 'username', 'password');

AH> Set cnn = Server.CreateObject("ADODB.Connection")
AH> cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
mysql_select_db('database_name', $link);

AH> Set rst = cnn.Execute("SELECT * FROM table WHERE Type ='" & type & "'
AH> order by style")
$sql= "SELECT * FROM table WHERE type='$type' ORDER BY style";
$result = mysql_query($sql);
You now have the entire "record set" in $result. To obtain the first
row of data, do this:
AH> <%Do While Not rstSimple.EOF%>
AH> do something
AH> <%
AH> rstSimple.MoveNext
AH> Loop
A few ways to do this:

$total_records = mysql_num_rows($result);

for ($i=0; $i < $total_records; $i++)
{
$data = mysql_fetch_assoc($result);
print_r($data);
}
$data will now be an array holding the first set of information. The
print_r line just displays it so you can see it easily.
Instead of a FOR loop you could do a "while" loop checking to see the
end of the $result set, i.e.:
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
  // do stuff
  print_r($row);
}
AH> <%=rst.fields("whatever").value%>



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] ASP to PHP language problems

2004-03-10 Thread Alistair Hayward
Richard Davey wrote:
A few ways to do this:

$total_records = mysql_num_rows($result);

for ($i=0; $i < $total_records; $i++)
{
$data = mysql_fetch_assoc($result);
print_r($data);
}
$data will now be an array holding the first set of information. The
print_r line just displays it so you can see it easily.
Instead of a FOR loop you could do a "while" loop checking to see the
end of the $result set, i.e.:
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
  // do stuff
  print_r($row);
}
AH> <%=rst.fields("whatever").value%>



I get this error: mysql_num_rows(): supplied argument is not a valid 
MySQL result resource

Question: Where you have the //do stuff comment, I assume this is where 
my HTML code will go. But can I put it between the open brackets? I.E:
{
html code
}

?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] ASP to PHP language problems

2004-03-10 Thread Alistair Hayward


Richard Davey wrote:
Hello Alistair,

Wednesday, March 10, 2004, 11:26:53 PM, you wrote:

AH> I get this error: mysql_num_rows(): supplied argument is not a valid
AH> MySQL result resource
Then your database connection failed OR the SQL query did. Check those
steps over before anything else.
Maybe post that part of your code so we can see?

AH> Question: Where you have the //do stuff comment, I assume this is where
AH> my HTML code will go. But can I put it between the open brackets? I.E:
AH> {
AH> html code
AH> }
Yes like so:

{
?>
html here

Just like in ASP :)



unset($type);
$type = $_GET['type'];
$link = mysql_connect('localhost', 'user', 'password');
if (!$link) {
echo "Couldn't make a connection!";
exit;
}
$db = mysql_select_db("sealhouse", $link);
if (!$db) {
echo "Couldn't select database!";
exit;
}
$sql= "SELECT * FROM table WHERE type=$type ORDER BY style";
$result = mysql_query($sql);
$total_records = mysql_num_rows($result);

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] ASP to PHP language problems

2004-03-10 Thread Alistair Hayward
Sorry, was the query!



Richard Davey wrote:

Hello Alistair,

Wednesday, March 10, 2004, 11:26:53 PM, you wrote:

AH> I get this error: mysql_num_rows(): supplied argument is not a valid
AH> MySQL result resource
Then your database connection failed OR the SQL query did. Check those
steps over before anything else.
Maybe post that part of your code so we can see?

AH> Question: Where you have the //do stuff comment, I assume this is 
where
AH> my HTML code will go. But can I put it between the open brackets? 
I.E:
AH> {
AH> html code
AH> }

Yes like so:

{
?>
html here

Just like in ASP :)



unset($type);
$type = $_GET['type'];
$link = mysql_connect('localhost', 'user', 'password');
if (!$link) {
echo "Couldn't make a connection!";
exit;
}
$db = mysql_select_db("sealhouse", $link);
if (!$db) {
echo "Couldn't select database!";
exit;
}
$sql= "SELECT * FROM table WHERE type=$type ORDER BY style";
$result = mysql_query($sql);
$total_records = mysql_num_rows($result);
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] ASP to PHP language problems

2004-03-10 Thread Alistair Hayward
To everyone, especially Richard,

Thanks a lot for the help. I have accomplished everything I needed to do 
with your help, and I have never used PHP before.

Thanks again!

alistair

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Adding a new entry using PHP

2004-04-07 Thread Alistair Hayward
Hi,

I am an ASP user, now learning PHP.

When adding a record in ASP, I do this:

Recordset.AddNew
Field1 = whatever
RecordSet.Update
How is this done in PHP?

I have built a recordset using a query, and have all the information 
needed to go into the different fields, but how do I 'Edit' or 'AddNew' 
and 'Update'?
This is what I have:



unset($price);
$price = $_GET['Price'];
unset($id);
$id = $_GET['id'];
unset($partnumber);
$partnumber = $_GET['PartNumber'];
unset($disc);
$disc = $_GET['Disc'];
$link = mysql_connect('localhost', 'root', 'password');
if (!$link) {
echo "Couldn't make a connection!";
exit;
}
$db = mysql_select_db("order", $link);
if (!$db) {
echo "Couldn't select database!";
exit;
}
$sql= "SELECT * FROM tborder WHERE sid='session.sessionid'";
$result = mysql_query($sql);
$total_records = mysql_num_rows($result);

?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php