php-general Digest 5 Oct 2002 18:44:28 -0000 Issue 1626
Topics (messages 118943 through 118960):
Re: Findng a pattern
118943 by: Rasmus Lerdorf
118951 by: Marek Kilimajer
Record Sorting Using Up and Down Arrows
118944 by: David Pratt
118954 by: Marek Kilimajer
Re: sending post without a form
118945 by: Jome
Re: Uploading Files
118946 by: Justin French
post(ing) data without a form
118947 by: Pablo Oliva
118948 by: Timothy J Hitchens
Array getting chopped up
118949 by: PHP
Looping?
118950 by: Steve Jackson
118952 by: Justin French
118955 by: Marek Kilimajer
118956 by: Marek Kilimajer
118957 by: . Edwin
118958 by: Marek Kilimajer
Re: unexpected t varable
118953 by: Marek Kilimajer
118959 by: Gary
More On: Good Practice: Variables, Error Reporting and Security
118960 by: Adam Royle
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
You are building something that will automatically scrape Google by
explicitly circumventing the tools they have provided for you to do so.
Whether the information is for your own internal statistics or not is
irrelevant. The terms of service state:
No Automated Querying
You may not send automated queries of any sort to Google's system
without express permission in advance from Google. Note that "sending automated
queries" includes, among other things:
* using any software which sends queries to Google to determine how
a website or webpage "ranks" on Google for various queries;
* "meta-searching" Google; and
* performing "offline" searches on Google.
-Rasmus
On Sat, 5 Oct 2002, Henry wrote:
> Dear Rasmus et.al.
>
> I am not wishing to reformat or display or mirror anything from google.
>
> This is for my own internal statistics.
>
> I hope that puts your mind at rest.
>
> Henry
>
> "Rasmus Lerdorf" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > You realize that you are asking us to help you violate the terms of
> > service of Google?
> >
> > A direct quote from their terms of service:
> >
> > "You may not take the results from a Google search and reformat and
> > display them, or mirror the Google home page or results pages on your
> > Web site."
> >
> > -Rasmus
> >
> > On Sat, 5 Oct 2002, Henry wrote:
> >
> > > Thanks, but I don't want to uses google's SOAP interface, is there a
> preg
> > > type solution.
> > >
> > >
> > > "Rasmus Lerdorf" <[EMAIL PROTECTED]> wrote in message
> > > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > > > Google has a SOAP interface for this.
> > > >
> > > > On Sat, 5 Oct 2002, Henry wrote:
> > > >
> > > > > Dear All,
> > > > >
> > > > > Excuse my ignorance but I'm STILL a newbie to this aspect of PHP.
> > > > >
> > > > > $str="Results <b>1</b> - <b>10</b> of about <b>14</b>. Search took
> > > > > <b>0.04</b> seconds."
> > > > >
> > > > > I would like to look for the string above in a buffer of text.
> However I
> > > > > would like to find it even if the numeric are different. Furthermore
> I
> > > would
> > > > > like to know what the values are. Is there a simple way to do this?
> > > > >
> > > > > TIA
> > > > >
> > > > > Henry
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > PHP General Mailing List (http://www.php.net/)
> > > > > To unsubscribe, visit: http://www.php.net/unsub.php
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
preg_match("Results <b>([0-9]+)</b> - <b>([0-9]+)</b> of about <b>([0-9]+)</b>.
Search took <b>([0-9]+)</b> seconds.",$string, $hits);
$hits[1], $hits[2], $hits[3], $hits[4] will contain your numbers
Henry wrote:
>Yes
>
>But that the string is contained within a much bigger string as well
>
>I want to search for the follwong string but with wild cards for the numeric
>values and I would like to know the values as well.
>
>"Results <b>$1</b> - <b>$2</b> of about <b>$3</b>. Search took <b>$4</b>
>seconds."
>
>Where all the $'s are numeric values
>
>Henry
>
>"Timothy J Hitchens" <[EMAIL PROTECTED]> wrote in message
>001001c26c2a$927a9ad0$0500a8c0@BAMBINO">news:001001c26c2a$927a9ad0$0500a8c0@BAMBINO...
>
>
>>Are you saying you want to be able to extract the numbers etc?
>>
>>
>>Timothy Hitchens (HiTCHO)
>>[EMAIL PROTECTED]
>>
>>HiTCHO has Spoken!
>>
>>
>>
>>
>>
>>
>>-----Original Message-----
>>From: Henry [mailto:[EMAIL PROTECTED]]
>>Sent: Saturday, 5 October 2002 2:36 PM
>>To: [EMAIL PROTECTED]
>>Subject: [PHP] Findng a pattern
>>
>>
>>Dear All,
>>
>>Excuse my ignorance but I'm STILL a newbie to this aspect of PHP.
>>
>>$str="Results <b>1</b> - <b>10</b> of about <b>14</b>. Search took
>><b>0.04</b> seconds."
>>
>>I would like to look for the string above in a buffer of text. However I
>>would like to find it even if the numeric are different. Furthermore I
>>would like to know what the values are. Is there a simple way to do
>>this?
>>
>>TIA
>>
>>Henry
>>
>>
>>
>>
>>
>>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>>
>>
>
>
>
>
>
--- End Message ---
--- Begin Message ---
Hi there. I am trying to write a routine to allow me to sort the contents of
a table by clicking on up or down arrows.
The idea is that top record will have down arrow, bottom record up arrow and
records inbetween both an up arrow and down arrow. Clicking the arrow
causes the record to move up or down one row in the table. The hyperlinks
on the arrows would be used to move the record up or down one by switching
the sort order values in the records ie. you want to move a record one up,
the value of the sort order would be switched with the record above.
I have created a numeric sort field that I initialize with the same value
and the id field in my table. I have my database content in an array that I
want to use. So I want to create the table using an array of rows. I can
get something basic to work if I do a count of my array to get the first and
last value. I do a foreach and test the values in a switch
like:
switch($itemcount) {
case 1:
if ($itemtotal == 1) {
$arrows = '';
} else {
$arrows = "$downarrow";
}
break;
case $itemtotal:
if ($itemtotal == 1) {
$arrows = '';
} else {
$arrows = "$uparrow";
}
break;
default:
$arrows = "$uparrow $downarrow";
break;
}
The problem I am having is to come up with a way to make this work when
there is more than one field to sort on. I have a table with a list of
functions and files. There is a many to one relationship between functions
and files and I want the up and down arrows to work for sorting the
functions in the files in the list. So that if a file has say 4 functions
the first would be down arrow, next two records would have both arrows, last
record for file uparrow, next record down arrow if file is different etc.
Could anyone help by giving me some advice on the best way of getting
something like this to work or have an example to follow. This would be
helpful. I have checked the archives first but could not find anything.
Regards,
DAve
--
Dave Pratt
--- End Message ---
--- Begin Message ---
PhpNuke has something like this in blocks management. Try looking at it.
David Pratt wrote:
>Hi there. I am trying to write a routine to allow me to sort the contents of
>a table by clicking on up or down arrows.
>The idea is that top record will have down arrow, bottom record up arrow and
>records inbetween both an up arrow and down arrow. Clicking the arrow
>causes the record to move up or down one row in the table. The hyperlinks
>on the arrows would be used to move the record up or down one by switching
>the sort order values in the records ie. you want to move a record one up,
>the value of the sort order would be switched with the record above.
>
>I have created a numeric sort field that I initialize with the same value
>and the id field in my table. I have my database content in an array that I
>want to use. So I want to create the table using an array of rows. I can
>get something basic to work if I do a count of my array to get the first and
>last value. I do a foreach and test the values in a switch
>like:
>
> switch($itemcount) {
>
> case 1:
> if ($itemtotal == 1) {
> $arrows = '';
> } else {
> $arrows = "$downarrow";
> }
> break;
> case $itemtotal:
> if ($itemtotal == 1) {
> $arrows = '';
> } else {
> $arrows = "$uparrow";
> }
> break;
> default:
> $arrows = "$uparrow $downarrow";
> break;
> }
>The problem I am having is to come up with a way to make this work when
>there is more than one field to sort on. I have a table with a list of
>functions and files. There is a many to one relationship between functions
>and files and I want the up and down arrows to work for sorting the
>functions in the files in the list. So that if a file has say 4 functions
>the first would be down arrow, next two records would have both arrows, last
>record for file uparrow, next record down arrow if file is different etc.
>Could anyone help by giving me some advice on the best way of getting
>something like this to work or have an example to follow. This would be
>helpful. I have checked the archives first but could not find anything.
>
>Regards,
>DAve
>
>
>
>
>
>
>--
>
>Dave Pratt
>
>
>
>
>
--- End Message ---
--- Begin Message ---
> Did the individual trying to send post(ed) data without the use of a
> form succeed? I tried doing this before and didn't have any luck with
> it... And I eventually gave up.
Check out Rasmus' solution: http://www.php-faq.com/postToHost.html
Jome
--- End Message ---
--- Begin Message ---
on 05/10/02 5:53 AM, Jason ([EMAIL PROTECTED]) wrote:
> I would like to be able to upload files from the client computer to the
> server via a form. I know how to build the form, but am not sure of the
> best way to process this. I know there are certain ftp functions that can
> do this, which I'm not sure how to use. Are there any others?
There's a perfect working example in the manual:
http://www.php.net/manual/en/features.file-upload.php
Justin French
--- End Message ---
--- Begin Message ---
OK, I'm attempting this again:
header ( 'Location: ../test/test.php' );
sendByPost();
function sendByPost()
{
$host = "localhost";
$port = 80;
$postdata = "field1=value1&field2=value2&field3=value3";
if ($sp = fsockopen($host, $port)) {
fputs($sp,"POST /jotr/test/test.php HTTP/1.0\n");
fputs($sp,"Host: $host\n");
fputs($sp,"Content-type: application/x-www-form-urlencoded\n");
fputs($sp,"Content-length: ".strlen($postdata)."\n");
fputs($sp,"Connection: close\n\n");
fputs($sp,$postdata);
fclose($sp);
}
}
Pretty straight forward. Now here's the code for test.php:
$temp1 = $_POST['field1'];
$temp2 = $_POST['field2'];
$temp3 = $_POST['field3'];
print $temp1.' '.$temp2.' '.$temp3;
But the data is not posting:
Notice: Undefined index: field1 in c:\apache\htdocs\jotr\test\test.php
on line 3
Notice: Undefined index: field2 in c:\apache\htdocs\jotr\test\test.php
on line 4
Notice: Undefined index: field3 in c:\apache\htdocs\jotr\test\test.php
on line 5
WTF is going on, shouldn't this work?
--- End Message ---
--- Begin Message ---
The other thing.. the header will redirect and the rest won't happen???
> header ( 'Location: ../test/test.php' );
Just out of interest sake do you or not have register global on/off??
Timothy Hitchens (HITCHO)
[EMAIL PROTECTED]
HITCHO has Spoken!
-----Original Message-----
From: Pablo Oliva [mailto:[EMAIL PROTECTED]]
Sent: Saturday, 5 October 2002 7:03 PM
To: [EMAIL PROTECTED]
Subject: [PHP] post(ing) data without a form
OK, I'm attempting this again:
header ( 'Location: ../test/test.php' );
sendByPost();
function sendByPost()
{
$host = "localhost";
$port = 80;
$postdata = "field1=value1&field2=value2&field3=value3";
if ($sp = fsockopen($host, $port)) {
fputs($sp,"POST /jotr/test/test.php HTTP/1.0\n");
fputs($sp,"Host: $host\n");
fputs($sp,"Content-type: application/x-www-form-urlencoded\n");
fputs($sp,"Content-length: ".strlen($postdata)."\n");
fputs($sp,"Connection: close\n\n");
fputs($sp,$postdata);
fclose($sp);
}
}
Pretty straight forward. Now here's the code for test.php: $temp1 =
$_POST['field1']; $temp2 = $_POST['field2']; $temp3 = $_POST['field3'];
print $temp1.' '.$temp2.' '.$temp3;
But the data is not posting:
Notice: Undefined index: field1 in c:\apache\htdocs\jotr\test\test.php
on line 3
Notice: Undefined index: field2 in c:\apache\htdocs\jotr\test\test.php
on line 4
Notice: Undefined index: field3 in c:\apache\htdocs\jotr\test\test.php
on line 5
WTF is going on, shouldn't this work?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Hello,
I'm having a problem on my server where any time there is more than one
element in an array, all elements prior to the last one get a portion of the
beginning chopped off. This portion is pretty random (I have yet to find any
pattern) other than it seems if there is a space it will chop off anything
before the first space in a particular element. Every time a new element is
added to the array, more characters are deleted from the previous one(s).
This is best shown by going to
http://66.192.46.41/~serverso/phpBB/index.php - create a new post and add a
poll to it. As you add options to the poll, you will see the effect on the
other options which you had already created. This is not a phpBB problem, as
it occurs in other non-related php files on the server, but as I said this
illustrates the effect well.
You can also see what it did to a menu in postnuke on the server at
www.dmcstop.com.
Does anyone have any ideas???
-Jordan
--- End Message ---
--- Begin Message ---
Anyone help me? this is probably quite simple but I'm pretty new to PHP.
All I want to do it loop through some DB records and display them in the
format written in this PHP file:
Anyone see where I'm going wrong? the error I get says:
Warning: Unable to jump to row 0 on MySQL result index 2
<?
$dbreturn = mysql_query("SELECT * FROM Items WHERE ItemID = '$ItemID'");
//debug
echo mysql_error();
$ItemHits = mysql_numrows($dbreturn);
$ItemID = mysql_result($dbreturn ,$i,"ItemID");
$ImageName = mysql_result($dbreturn ,$i,"ImageName");
$ItemName = mysql_result($dbreturn ,$i,"ItemName");
$ItemSKU = mysql_result($dbreturn ,$i,"ItemSKU");
$ItemCost = mysql_result($dbreturn ,$i,"ItemCost");
$ItemDescription = mysql_result($dbreturn
,$i,"ItemDescription");
for ($i=0; $i < $ItemHits; $i++)
//($i < $ItemHits)
{
$row = mysql_fetch_array($dbreturn);
echo "<table width='400' border='0' cellspacing='0' cellpadding='0'>";
echo "<tr>";
echo "<td><img src='images/$ImageName' width='175'></td>";
echo "<td valign='top'>";
echo "<table width='225' border='0' cellspacing='0' cellpadding='0'>";
echo "<tr>";
echo "<td><span class='pikkuleipa'>Product Name:</span></td>";
echo "<td><span class='pikkuleipa'>$ItemName</span></td>";
echo "</tr>";
echo "<tr>";
echo "<td><span class='pikkuleipa'>Product Code:</span></td>";
echo "<td><span class='pikkuleipa'>$ItemSKU</span></td>";
echo "</tr>";
echo "<tr>";
echo "<td><span class='pikkuleipa'>Unit price:</span></td>";
echo "<td><span class='pikkuleipa'>€$ItemCost</span></td>";
echo "</tr>";
echo "<tr>";
echo "<td><span class='pikkuleipa'><b>Description</b></span><br></td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<table width='225' border='0' cellspacing='0' cellpadding='0'>";
echo "<tr>";
echo "<td><span class='pikkuleipa'>$ItemDescription</span></td>";
echo "</tr>";
echo "</table>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<form method='post' action='$Relative/addcart.php'>";
echo "<table width='400' border='0' cellspacing='0' cellpadding='0'>";
echo "<tr>";
echo "<td width='175' align='right'><span class='pikkuleipa'>Quantity
Required:</span></td>";
echo "<td width='225'>";
echo "<INPUT TYPE='TEXT' Name='ItemQuantity' Value='1' size='2'>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td width='175'></td>";
echo "<td width='225'><input type='image' border='0' name='submit'
src='images/add.gif'></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
//$i++;
}
?>
--- End Message ---
--- Begin Message ---
This should get you started:
<?
$dbreturn = mysql_query("SELECT * FROM Items WHERE ItemID = '$ItemID'");
echo mysql_error();
$ItemHits = mysql_numrows($dbreturn);
while($row = mysql_fetch_array($dbreturn))
{
$ItemID = $row['ItemID'];
$ImageName = $row['ImageName'];
$ItemName = $row['ItemName'];
$ItemSKU = $row['ItemSKU'];
$ItemCost = $row['ItemCost'];
$ItemDescription = $row['ItemDescription'];
echo "<table width='400' border='0' cellspacing='0' cellpadding='0'>";
echo "<tr>";
echo "<td><img src='images/$ImageName' width='175'></td>";
echo "<td valign='top'>";
echo "<table width='225' border='0' cellspacing='0' cellpadding='0'>";
echo "<tr>";
echo "<td><span class='pikkuleipa'>Product Name:</span></td>";
echo "<td><span class='pikkuleipa'>$ItemName</span></td>";
echo "</tr>";
echo "<tr>";
echo "<td><span class='pikkuleipa'>Product Code:</span></td>";
echo "<td><span class='pikkuleipa'>$ItemSKU</span></td>";
echo "</tr>";
echo "<tr>";
echo "<td><span class='pikkuleipa'>Unit price:</span></td>";
echo "<td><span class='pikkuleipa'>€$ItemCost</span></td>";
echo "</tr>";
echo "<tr>";
echo "<td><span class='pikkuleipa'><b>Description</b></span><br></td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<table width='225' border='0' cellspacing='0' cellpadding='0'>";
echo "<tr>";
echo "<td><span class='pikkuleipa'>$ItemDescription</span></td>";
echo "</tr>";
echo "</table>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<form method='post' action='$Relative/addcart.php'>";
echo "<table width='400' border='0' cellspacing='0' cellpadding='0'>";
echo "<tr>";
echo "<td width='175' align='right'><span class='pikkuleipa'>Quantity
Required:</span></td>";
echo "<td width='225'>";
echo "<INPUT TYPE='TEXT' Name='ItemQuantity' Value='1' size='2'>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td width='175'></td>";
echo "<td width='225'><input type='image' border='0' name='submit'
src='images/add.gif'></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
}
?>
Justin
on 05/10/02 10:56 PM, Steve Jackson ([EMAIL PROTECTED]) wrote:
> Anyone help me? this is probably quite simple but I'm pretty new to PHP.
> All I want to do it loop through some DB records and display them in the
> format written in this PHP file:
> Anyone see where I'm going wrong? the error I get says:
> Warning: Unable to jump to row 0 on MySQL result index 2
>
> <?
>
> $dbreturn = mysql_query("SELECT * FROM Items WHERE ItemID = '$ItemID'");
> //debug
> echo mysql_error();
> $ItemHits = mysql_numrows($dbreturn);
> $ItemID = mysql_result($dbreturn ,$i,"ItemID");
> $ImageName = mysql_result($dbreturn ,$i,"ImageName");
> $ItemName = mysql_result($dbreturn ,$i,"ItemName");
> $ItemSKU = mysql_result($dbreturn ,$i,"ItemSKU");
> $ItemCost = mysql_result($dbreturn ,$i,"ItemCost");
> $ItemDescription = mysql_result($dbreturn ,$i,"ItemDescription");
> for ($i=0; $i < $ItemHits; $i++)
> //($i < $ItemHits)
> {
> $row = mysql_fetch_array($dbreturn);
> echo "<table width='400' border='0' cellspacing='0' cellpadding='0'>";
> echo "<tr>";
> echo "<td><img src='images/$ImageName' width='175'></td>";
> echo "<td valign='top'>";
> echo "<table width='225' border='0' cellspacing='0' cellpadding='0'>";
> echo "<tr>";
> echo "<td><span class='pikkuleipa'>Product Name:</span></td>";
> echo "<td><span class='pikkuleipa'>$ItemName</span></td>";
> echo "</tr>";
> echo "<tr>";
> echo "<td><span class='pikkuleipa'>Product Code:</span></td>";
> echo "<td><span class='pikkuleipa'>$ItemSKU</span></td>";
> echo "</tr>";
> echo "<tr>";
> echo "<td><span class='pikkuleipa'>Unit price:</span></td>";
> echo "<td><span class='pikkuleipa'>€$ItemCost</span></td>";
> echo "</tr>";
> echo "<tr>";
> echo "<td><span class='pikkuleipa'><b>Description</b></span><br></td>";
> echo "</tr>";
> echo "<tr>";
> echo "<td>";
> echo "</td>";
> echo "</tr>";
> echo "</table>";
> echo "<table width='225' border='0' cellspacing='0' cellpadding='0'>";
> echo "<tr>";
> echo "<td><span class='pikkuleipa'>$ItemDescription</span></td>";
> echo "</tr>";
> echo "</table>";
> echo "</td>";
> echo "</tr>";
> echo "</table>";
> echo "<form method='post' action='$Relative/addcart.php'>";
> echo "<table width='400' border='0' cellspacing='0' cellpadding='0'>";
> echo "<tr>";
> echo "<td width='175' align='right'><span class='pikkuleipa'>Quantity
> Required:</span></td>";
> echo "<td width='225'>";
> echo "<INPUT TYPE='TEXT' Name='ItemQuantity' Value='1' size='2'>";
> echo "</td>";
> echo "</tr>";
> echo "<tr>";
> echo "<td width='175'></td>";
> echo "<td width='225'><input type='image' border='0' name='submit'
> src='images/add.gif'></td>";
> echo "</tr>";
> echo "</table>";
> echo "</form>";
> //$i++;
> }
> ?>
>
--- End Message ---
--- Begin Message ---
typo:
Justin French wrote:
>This should get you started:
>
>
>
><?
>$dbreturn = mysql_query("SELECT * FROM Items WHERE ItemID = '$ItemID'");
>echo mysql_error();
>$ItemHits = mysql_numrows($dbreturn);
>
mysql_num_rows()
>while($row = mysql_fetch_array($dbreturn))
>{
>$ItemID = $row['ItemID'];
>$ImageName = $row['ImageName'];
>$ItemName = $row['ItemName'];
>$ItemSKU = $row['ItemSKU'];
>$ItemCost = $row['ItemCost'];
>$ItemDescription = $row['ItemDescription'];
>
>echo "<table width='400' border='0' cellspacing='0' cellpadding='0'>";
>echo "<tr>";
>echo "<td><img src='images/$ImageName' width='175'></td>";
>echo "<td valign='top'>";
>echo "<table width='225' border='0' cellspacing='0' cellpadding='0'>";
>echo "<tr>";
>echo "<td><span class='pikkuleipa'>Product Name:</span></td>";
>echo "<td><span class='pikkuleipa'>$ItemName</span></td>";
>echo "</tr>";
>echo "<tr>";
>echo "<td><span class='pikkuleipa'>Product Code:</span></td>";
>echo "<td><span class='pikkuleipa'>$ItemSKU</span></td>";
>echo "</tr>";
>echo "<tr>";
>echo "<td><span class='pikkuleipa'>Unit price:</span></td>";
>echo "<td><span class='pikkuleipa'>¬$ItemCost</span></td>";
>echo "</tr>";
>echo "<tr>";
>echo "<td><span class='pikkuleipa'><b>Description</b></span><br></td>";
>echo "</tr>";
>echo "<tr>";
>echo "<td>";
>echo "</td>";
>echo "</tr>";
>echo "</table>";
>echo "<table width='225' border='0' cellspacing='0' cellpadding='0'>";
>echo "<tr>";
>echo "<td><span class='pikkuleipa'>$ItemDescription</span></td>";
>echo "</tr>";
>echo "</table>";
>echo "</td>";
>echo "</tr>";
>echo "</table>";
>echo "<form method='post' action='$Relative/addcart.php'>";
>echo "<table width='400' border='0' cellspacing='0' cellpadding='0'>";
>echo "<tr>";
>echo "<td width='175' align='right'><span class='pikkuleipa'>Quantity
>Required:</span></td>";
>echo "<td width='225'>";
>echo "<INPUT TYPE='TEXT' Name='ItemQuantity' Value='1' size='2'>";
>echo "</td>";
>echo "</tr>";
>echo "<tr>";
>echo "<td width='175'></td>";
>echo "<td width='225'><input type='image' border='0' name='submit'
>src='images/add.gif'></td>";
>echo "</tr>";
>echo "</table>";
>echo "</form>";
>}
>
>?>
>
>Justin
>
>
>
>on 05/10/02 10:56 PM, Steve Jackson ([EMAIL PROTECTED]) wrote:
>
>
>
>>Anyone help me? this is probably quite simple but I'm pretty new to PHP.
>>All I want to do it loop through some DB records and display them in the
>>format written in this PHP file:
>>Anyone see where I'm going wrong? the error I get says:
>>Warning: Unable to jump to row 0 on MySQL result index 2
>>
>><?
>>
>>$dbreturn = mysql_query("SELECT * FROM Items WHERE ItemID = '$ItemID'");
>>//debug
>>echo mysql_error();
>>$ItemHits = mysql_numrows($dbreturn);
>>$ItemID = mysql_result($dbreturn ,$i,"ItemID");
>>$ImageName = mysql_result($dbreturn ,$i,"ImageName");
>>$ItemName = mysql_result($dbreturn ,$i,"ItemName");
>>$ItemSKU = mysql_result($dbreturn ,$i,"ItemSKU");
>>$ItemCost = mysql_result($dbreturn ,$i,"ItemCost");
>>$ItemDescription = mysql_result($dbreturn ,$i,"ItemDescription");
>>for ($i=0; $i < $ItemHits; $i++)
>>//($i < $ItemHits)
>>{
>>$row = mysql_fetch_array($dbreturn);
>>echo "<table width='400' border='0' cellspacing='0' cellpadding='0'>";
>>echo "<tr>";
>>echo "<td><img src='images/$ImageName' width='175'></td>";
>>echo "<td valign='top'>";
>>echo "<table width='225' border='0' cellspacing='0' cellpadding='0'>";
>>echo "<tr>";
>>echo "<td><span class='pikkuleipa'>Product Name:</span></td>";
>>echo "<td><span class='pikkuleipa'>$ItemName</span></td>";
>>echo "</tr>";
>>echo "<tr>";
>>echo "<td><span class='pikkuleipa'>Product Code:</span></td>";
>>echo "<td><span class='pikkuleipa'>$ItemSKU</span></td>";
>>echo "</tr>";
>>echo "<tr>";
>>echo "<td><span class='pikkuleipa'>Unit price:</span></td>";
>>echo "<td><span class='pikkuleipa'>¬$ItemCost</span></td>";
>>echo "</tr>";
>>echo "<tr>";
>>echo "<td><span class='pikkuleipa'><b>Description</b></span><br></td>";
>>echo "</tr>";
>>echo "<tr>";
>>echo "<td>";
>>echo "</td>";
>>echo "</tr>";
>>echo "</table>";
>>echo "<table width='225' border='0' cellspacing='0' cellpadding='0'>";
>>echo "<tr>";
>>echo "<td><span class='pikkuleipa'>$ItemDescription</span></td>";
>>echo "</tr>";
>>echo "</table>";
>>echo "</td>";
>>echo "</tr>";
>>echo "</table>";
>>echo "<form method='post' action='$Relative/addcart.php'>";
>>echo "<table width='400' border='0' cellspacing='0' cellpadding='0'>";
>>echo "<tr>";
>>echo "<td width='175' align='right'><span class='pikkuleipa'>Quantity
>>Required:</span></td>";
>>echo "<td width='225'>";
>>echo "<INPUT TYPE='TEXT' Name='ItemQuantity' Value='1' size='2'>";
>>echo "</td>";
>>echo "</tr>";
>>echo "<tr>";
>>echo "<td width='175'></td>";
>>echo "<td width='225'><input type='image' border='0' name='submit'
>>src='images/add.gif'></td>";
>>echo "</tr>";
>>echo "</table>";
>>echo "</form>";
>>//$i++;
>>}
>>?>
>>
>>
>>
>
>
>
>
--- End Message ---
--- Begin Message ---
Just checked the manual and there are no functions named *mysql_numrows*
or *mysql_num_row*, but
only *mysql_num_rows* (notice the S at the end)
Steve Jackson wrote:
>Nope doesn't make any difference
>mysql_numrows or mysql_num_row returns the same:
>
>In this case nothing!
>
>
>
>>-----Original Message-----
>>From: Marek Kilimajer [mailto:[EMAIL PROTECTED]]
>>Sent: 05 October 2002 17:03
>>To: PHP
>>Subject: Re: [PHP] Looping?
>>
>>
>>typo:
>>
>>Justin French wrote:
>>
>>
>>
>>>This should get you started:
>>>
>>>
>>>
>>><?
>>>$dbreturn = mysql_query("SELECT * FROM Items WHERE ItemID = '$ItemID'");
>>>echo mysql_error();
>>>$ItemHits = mysql_numrows($dbreturn);
>>>
>>>
>>>
>>mysql_num_rows()
>>
>>
>>
>>>while($row = mysql_fetch_array($dbreturn))
>>>{
>>>$ItemID = $row['ItemID'];
>>>$ImageName = $row['ImageName'];
>>>$ItemName = $row['ItemName'];
>>>$ItemSKU = $row['ItemSKU'];
>>>$ItemCost = $row['ItemCost'];
>>>$ItemDescription = $row['ItemDescription'];
>>>
>>>echo "<table width='400' border='0' cellspacing='0' cellpadding='0'>";
>>>echo "<tr>";
>>>echo "<td><img src='images/$ImageName' width='175'></td>";
>>>echo "<td valign='top'>";
>>>echo "<table width='225' border='0' cellspacing='0' cellpadding='0'>";
>>>echo "<tr>";
>>>echo "<td><span class='pikkuleipa'>Product Name:</span></td>";
>>>echo "<td><span class='pikkuleipa'>$ItemName</span></td>";
>>>echo "</tr>";
>>>echo "<tr>";
>>>echo "<td><span class='pikkuleipa'>Product Code:</span></td>";
>>>echo "<td><span class='pikkuleipa'>$ItemSKU</span></td>";
>>>echo "</tr>";
>>>echo "<tr>";
>>>echo "<td><span class='pikkuleipa'>Unit price:</span></td>";
>>>echo "<td><span class='pikkuleipa'>¬$ItemCost</span></td>";
>>>echo "</tr>";
>>>echo "<tr>";
>>>echo "<td><span class='pikkuleipa'><b>Description</b></span><br></td>";
>>>echo "</tr>";
>>>echo "<tr>";
>>>echo "<td>";
>>>echo "</td>";
>>>echo "</tr>";
>>>echo "</table>";
>>>echo "<table width='225' border='0' cellspacing='0' cellpadding='0'>";
>>>echo "<tr>";
>>>echo "<td><span class='pikkuleipa'>$ItemDescription</span></td>";
>>>echo "</tr>";
>>>echo "</table>";
>>>echo "</td>";
>>>echo "</tr>";
>>>echo "</table>";
>>>echo "<form method='post' action='$Relative/addcart.php'>";
>>>echo "<table width='400' border='0' cellspacing='0' cellpadding='0'>";
>>>echo "<tr>";
>>>echo "<td width='175' align='right'><span class='pikkuleipa'>Quantity
>>>Required:</span></td>";
>>>echo "<td width='225'>";
>>>echo "<INPUT TYPE='TEXT' Name='ItemQuantity' Value='1' size='2'>";
>>>echo "</td>";
>>>echo "</tr>";
>>>echo "<tr>";
>>>echo "<td width='175'></td>";
>>>echo "<td width='225'><input type='image' border='0' name='submit'
>>>src='images/add.gif'></td>";
>>>echo "</tr>";
>>>echo "</table>";
>>>echo "</form>";
>>>}
>>>
>>>?>
>>>
>>>
>>>
>
>
>
--- End Message ---
--- Begin Message ---
Actually, there *is* ("mysql_numrows").
I think you've missed this one. ;)
http://www.php.net/manual/en/printwn/aliases.php
- E
On Saturday, October 05, 2002 11:40 PM
Subject: Re: [PHP] Looping?
Marek Kilimajer wrote:
> Just checked the manual and there are no functions named *mysql_numrows*
> or *mysql_num_row*, but
> only *mysql_num_rows* (notice the S at the end)
>
> Steve Jackson wrote:
>
> >Nope doesn't make any difference
> >mysql_numrows or mysql_num_row returns the same:
> >
> >In this case nothing!
> >
> >
> >
[/snip]
--- End Message ---
--- Begin Message ---
Thanks, never been there ;)
@ Edwin wrote:
>Actually, there *is* ("mysql_numrows").
>
>I think you've missed this one. ;)
>
> http://www.php.net/manual/en/printwn/aliases.php
>
>- E
>
>On Saturday, October 05, 2002 11:40 PM
>Subject: Re: [PHP] Looping?
>Marek Kilimajer wrote:
>
>
>
>>Just checked the manual and there are no functions named *mysql_numrows*
>>or *mysql_num_row*, but
>>only *mysql_num_rows* (notice the S at the end)
>>
>>Steve Jackson wrote:
>>
>>
>>
>>>Nope doesn't make any difference
>>>mysql_numrows or mysql_num_row returns the same:
>>>
>>>In this case nothing!
>>>
>>>
>>>
>>>
>>>
>[/snip]
>
>
>
--- End Message ---
--- Begin Message ---
what about
if( $res->numRows() {
while( $row = $res->fetchRows() ){
... do what you've got to do
}
} else {
... no rows
}
Gary wrote:
> John W. Holmes wrote:
>
>>> John W. Holmes wrote:
>>>
>>>
>>>>> Can someone tell where I messed up on this code snippit?
>>>>>
>>>>
>>>> Your first mistake is not giving us the full error and the line
>>>> number...
>>>>
>>>>
>>>>
>>>>
>>>>> if ($res->numRows() > 0){
>>>>> list($id, $question, $responce1,
>>>>>
>>>>
>>>> $responce2,
>>>>
>>>>
>>>>
>>>>> $responce3) = $res->fetchRows()
>>>>>
>>>>
>>>> and you're missing a ; here... ^^
>>>>
>>>>
>>>>
>>>>
>>>>> $id = $row[0];
>>>>> $question = $row[1];
>>>>> $responce1 = $row[2];
>>>>> $responce2 = $row[3];
>>>>> $responce3 = $row[4];
>>>>> }
>>>>>
>>>>
>>>> ---John Holmes...
>>>>
>>>>
>>>>
>>>
>>> that fixed the unexpected t_variable but now it is Fatal error: Call
>>>
>>
>> to
>>
>>
>>> undefined function: fetchrows()
>>>
>>> list($id, $question, $responce1, $responce2,$responce3) = $res-
>>>
>>>
>>>> fetchRows()
>>>>
>>>
>>
>> That means there is no function fetchrows() associated with whatever
>> class $res comes from...
>>
>>
>
> I think it is time to call it a day. It is 11pm and I am getting so
> punchy from this long day, I forgot to say it is a db call using
> pearDB. If I remove the code and replace it with while ($row =
> $res->fetchRows()) along the row array it work but then I can't check
> for > 0
>
>
> Sorry
> Gary
>
>>
>>
>>
>>
>>
>
>
>
>
--- End Message ---
--- Begin Message ---
Doesn't work, get unexpected { for if( $res->numRows() {. If I remove
braces or rearrange them it fall apart piece by piece.
Thanks for the try
Gary
Marek Kilimajer wrote:
> what about
>
> if( $res->numRows() {
> while( $row = $res->fetchRows() ){
> ... do what you've got to do
> }
> } else {
> ... no rows
> }
>
> Gary wrote:
>
>> John W. Holmes wrote:
>>
>>>> John W. Holmes wrote:
>>>>
>>>>
>>>>>> Can someone tell where I messed up on this code snippit?
>>>>>>
>>>>>
>>>>>
>>>>> Your first mistake is not giving us the full error and the line
>>>>> number...
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> if ($res->numRows() > 0){
>>>>>> list($id, $question, $responce1,
>>>>>>
>>>>>
>>>>>
>>>>> $responce2,
>>>>>
>>>>>
>>>>>
>>>>>> $responce3) = $res->fetchRows()
>>>>>>
>>>>>
>>>>>
>>>>> and you're missing a ; here... ^^
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> $id = $row[0];
>>>>>> $question = $row[1];
>>>>>> $responce1 = $row[2];
>>>>>> $responce2 = $row[3];
>>>>>> $responce3 = $row[4];
>>>>>> }
>>>>>>
>>>>>
>>>>>
>>>>> ---John Holmes...
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> that fixed the unexpected t_variable but now it is Fatal error: Call
>>>>
>>>
>>>
>>> to
>>>
>>>
>>>> undefined function: fetchrows()
>>>>
>>>> list($id, $question, $responce1, $responce2,$responce3) = $res-
>>>>
>>>>
>>>>> fetchRows()
>>>>>
>>>>
>>>>
>>>
>>> That means there is no function fetchrows() associated with whatever
>>> class $res comes from...
>>>
>>>
>>
>> I think it is time to call it a day. It is 11pm and I am getting so
>> punchy from this long day, I forgot to say it is a db call using
>> pearDB. If I remove the code and replace it with while ($row =
>> $res->fetchRows()) along the row array it work but then I can't check
>> for > 0
>>
>>
>> Sorry
>> Gary
>>
--- End Message ---
--- Begin Message ---
I very much appreciate the suggestions made by the people on this list,
although for me, when developing, the less typing I have to do, the
less errors I am bound to come across, and therefore the less debugging
I must do. (Now, doesn't this seem sensible?)
Anyway, I have developed a function and incorporated Maxim's code
(thankyou) to make importing variables (into global scope) easier (with
register_globals turned off).
I have it sitting in my lib.php which contains all common functions
(database functions, etc) that I use with my scripts and is included on
every page I write.
To use my function, simply write:
importVars($_GET, 'var1,var2,var3'); // this will get var1, var2 and
var3 from the querystring
importVars($_SESSION); // this will import all session information
This was tested with error_reporting set to E_ALL. Often in my code I
will do something like this.
if ($flag){
// do certain code relating to $flag
}
If $flag has not been initialized, this check will produce a NOTICE
error, which appears if you are using E_ALL. So, my function will take
all the variables you pass to it (through the comma-delimited string)
and either import the variables (if it exists) or create an empty
variable (zero-length string). This way you can do the check. I know
some people will say, you could just use if (isset($flag)), but I like
take advantage of PHP's automatic type conversion.
Another feature of my function is if you don't supply a string to vars
to import, it will bring in everything from that array. This lets
people import all the variables they want, and they don't care about
security, or are protecting it through other means (extensive var
checks) etc.
ie. importVars($_GET);
So I hope this stuff helps some people out there.
Also, can anyone see any problems with my function? (Performance-wise
or security-wise).
Adam
/*
Credit given to: Maxim Maletsky <[EMAIL PROTECTED]>
Alter variables for the versions prior to 4.1.0
NOTE: $_REQUEST global variable is NOT supported.
*/
if (strnatcasecmp('4.1.0', PHP_VERSION) >= 0) {
foreach(Array(
'_GET' => 'HTTP_GET_VARS',
'_POST' => 'HTTP_POST_VARS',
'_COOKIE' => 'HTTP_COOKIE_VARS',
'_SESSION' => 'HTTP_SESSION_VARS',
'_SERVER' => 'HTTP_SERVER_VARS',
'_ENV' => 'HTTP_ENV_VARS',
'_FILES' => 'HTTP_POST_FILES'
) as $transvar['new'] => $transvar['old']) {
if (isset($$transvar['old']) and is_array($$transvar['old'])) {
$GLOBALS[$transvar['new']] = &$$transvar['old'];
}
}
// Unset transvar, we do not need it anymore.
unset($transvar);
}
/*
function importVars()
Written by: Adam Royle <[EMAIL PROTECTED]>
Imports vars from $arrVarType into the global scope.
Example: importVars($_GET, 'page,ID,num');
Will create the three variables $page, $ID and $num, and will fill them
with data from the querystring. If there is no data in the querystring,
it will create a zero-length string.
*/
function importVars(&$arrVarType, $strVarList='')
{
if (!trim($strVarList)){
// import all variables from $arrVarType
foreach($arrVarType as $var => $value){
$GLOBALS[$var] = $value;
}
} else {
// only import variables in $strVarList
$arrVarList = explode(',',$strVarList);
foreach($arrVarList as $var){
$var = trim($var);
if (isset($arrVarType[$var])){
$GLOBALS[$var] = $arrVarType[$var];
} else {
$GLOBALS[$var] = '';
}
}
}
}
--- End Message ---