php-general Digest 25 Dec 2006 21:10:05 -0000 Issue 4534
Topics (messages 246205 through 246212):
Re: calling a function in the same page
246205 by: Sumeet
246212 by: Peter Lauri
Re: Clarification: Jump to a record/PHP paging...
246206 by: Robert Cummings
Merry Christmas!
246207 by: Robert Cummings
scripting process doesn't function
246208 by: Geert T
246210 by: Sancar Saran
Re: Odd behavior
246209 by: Roman Neuhauser
246211 by: jekillen
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 ---
Jahangir wrote:
I am trying to call a function from "a href" inside the same page.
this is the code:
echo "<br><br><a href=\"isearch($query)\">More results from Mysite</a>";
// calling the function isearch
function isearch($query)
{$query=urlencode($query);
$request='http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=Ja
hangir&query=' .urlencode($query). '&output=php&results=100&site=mysite.com;
$response=file_get_contents($request);
if ($response === false) {
die('Request failed');}
$phpobj=unserialize($response);
$count=$phpobj["ResultSet"]["totalResultsReturned"];
if($phpobj["ResultSet"]["totalResultsAvailable"]==0)
{echo "<br>NO RESULTS TO DISPLAY"; }
add a 'die;' here.. like
{
echo "<br>NO RESULTS TO DISPLAY";
die;
}
--
Thanking You
Sumeet Shroff
http://www.prateeksha.com
Web Designers and PHP / Mysql Ecommerce Development, Mumbai India
--- End Message ---
--- Begin Message ---
Hi,
Are you trying to use PHP as a client scripting language?
What you are doing cannot be done with plain PHP, you have to invoke
JavaScript or similar to make a HTTP request and then parse it.
Search Google for "AJAX" and you could get it working using that. Prototype
is a easy to use JS library that you can do "AJAX" requests with and then do
what you want with by DOM.
/Peter
-----Original Message-----
From: Jahangir [mailto:[EMAIL PROTECTED]
Sent: Sunday, December 24, 2006 5:34 PM
To: [email protected]
Subject: [PHP] calling a function in the same page
I am trying to call a function from "a href" inside the same page.
this is the code:
echo "<br><br><a href=\"isearch($query)\">More results from Mysite</a>";
// calling the function isearch
function isearch($query)
{$query=urlencode($query);
$request='http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=Ja
hangir&query=' .urlencode($query). '&output=php&results=100&site=mysite.com;
$response=file_get_contents($request);
if ($response === false) {
die('Request failed');}
$phpobj=unserialize($response);
$count=$phpobj["ResultSet"]["totalResultsReturned"];
if($phpobj["ResultSet"]["totalResultsAvailable"]==0)
{echo "<br>NO RESULTS TO DISPLAY"; }
echo "<tr>"; echo "<h4 style=\"color:#FF0000\" align=\"center\">Results from
Mysite</h4>";
for($i=0;$i<$count;$i++)
{ echo '<pre>';
$no=$i+1;
$url=$phpobj["ResultSet"]["Result"]["$i"]["Url"];
echo "<h3>" ."$no. ". "<a href=\"$url\">" .
$phpobj["ResultSet"]["Result"]["$i"]["Title"] . "</a></h3>"; echo "</tr>";
echo "<tr>"; echo $phpobj["ResultSet"]["Result"]["$i"]["Summary"]; echo
"</tr>";
echo "<br>"; echo "<tr>"; echo "<b>"
.$phpobj["ResultSet"]["Result"]["$i"]["Url"] ."</b>"; echo "</tr>";
echo "<br>"; $link=$phpobj["ResultSet"]["Result"]["$i"]["DisplayUrl"];
echo "<tr>"; echo "<a href=\"$url\">$link</a>"; echo "</tr>";
echo '</pre>'; }}
whenever i try to execute this function i either get an "Object not found
error" or "Access Forbidden error".
Can someone tell me where am i going wrong here??
thanks in advance
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
On Sun, 2006-12-24 at 11:22 -0500, tedd wrote:
> > > Again, in my opinion, that's fuzzy thinking. Sure, Yeti may be in the
> >> monster sub-set, but how much monster it is as compared to Lockness?
> >> You need a means, a yardstick, to compare the two with each other.
> >> Like, is Lockness bigger than the Yeti while monster-mouse is
> >> smaller, or what?
> >
> >Who the hell cares, I asked for any entry with monster in the
> >description, I didn't say make higher level philosophical debate within
> >your head as to the level of monsteriness. Quit trying to paint shades
> >of gray when all that lies before you is black and white. We have an
> >order, the order in the dictionary, we have a query for which results
> >are returned using the same ordering criterion as in the dictionary.
>
> Rob:
>
> If YOU are doing a FULL TEXT search within a description field
> looking for the word "monster" and reporting all those records that
> fulfill the search, then I agree with YOU, but that's not what the
> POSTER was asking. In fact, I already discussed a FULL TEXT search in
> a previous post re this subject.
>
> The poster asked:
>
> >... my question is: how might I have MySQL tell me how many records
> >came BEFORE the found record?
>
> So, if he followed your advice/technique, then tell us how many
> records came before "monster"?
>
> I claim you can't.
WRONG! See Martin Alterisio's post for the same thread. You must not
have understood the OP's requirements.
> >He has already decided an order so your rebuttal is completely devoid of
> >additional content.
>
> You are arbitrarily inferring that the order was alphabetical, but he
> did not say that.
>
> However, if he had, then please explain how you would use a FULL TEXT
> search to find the word that came BEFORE "monster"? I would be very
> interested to see how that's done. We all can learn.
Yep, you definitely didn't understand the requirements. Tsk tsk.
BTW,
Merry Christmas :D
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--- End Message ---
--- Begin Message ---
WoooohoooooooooooooooooooOO! Hope you all have a great Christmas day. If
you don't celebrate Christmas, then I hope you have a great Christmas
day anyways *lol*. If this post offends you due to it's promotion of
Christmas then I apologize and hope you have a great anal retentive
Christmas day!!! :B
Merry Christmas,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--- End Message ---
--- Begin Message ---
Hi,
I have made some script that process the users input, and validates the input
and sends it back. But it doesn't work very
well, in fact it doesn't work at all. I am only able to see and input my name
and such in the html form, but the php part doesn't do it's job.
I have looked over the scripts thousands of times, but couldn't find the
problem, really.
Here is the script plus 2 .inc files;
Hoping for some replies and answers,
Thanks in advance!
PS: if this script is a bit messy to read, I have included them in this mail
seperately.
<?php/* Script name: addressForm.inc * Description: Script displays a form. */
echo "<html> <head><title>Customer Address</title></head> <body>";
echo "<p align='center'> <form action='validateForm.php' method='POST'>
<table width='95%' border='0' cellspacing='0' cellpadding='2'\n";
foreach($labels as $field=>$value) { if(isset($_POST[$field])) { $value =
$_POST[$field]; } else { $value = ""; } echo "<tr><td
align='right'>{$labels[$field]}</br></td> <td><input type='text'
name'$field' size='65' maxlength='65' value='$value'> </td> </tr>";
} echo " </table> <div align='center'> <p><input type='Submit'
name='Submit' value='Submit Address'></p></div>
</form>";?></body></html>
<?php/* Script name: info.inc * Description: creates an array of labels for
use in a * form. */
$labels = array( "firstName"=> "First Name:", "midName"=>"Middle Name:",
"lastName"=>"Last Name:", "street"=>"Street Address:",
"city"=>"City:", "state"=>"State:", "zipcode"=>"Zipcode:"); ?>
<?php/* Script name: validateForm * Description: Displays and validates a form
that * collects a name and address. */ include("info.inc"); #6
################################# ## First display of empty form ##
################################# if(!isset($_POST['Submit'])) #10 {
include("addressForm.inc"); }
######################################################## ## Check information
when form is submitted. Build ## ## arrays of blank and incorrectly formatted
fields. ## ## If any errors are found, display error messages ## ## and
redisplay form. If no errors found, display ## ## the submitted information.
## ######################################################## else
#21 { foreach($_POST as $field=>$value) #23 {
if(empty($_POST[$field])) #25 { if($field !="midName") {
$blanks[$field] = "blank"; #29 } } else #33 { $value =
trim($value); if($field != "zipcode") { if(!ereg("^[A-Za-z0-9'
.-]{1,65}$",$value)) { $formats[$field] = "bad"; } }
elseif($field == "zipcode") { if(!ereg("^[0-9]{5}(\-[0-9]{4})?",$value))
{ $formats[$field] = "bad"; } } } } #51 ### if any fields
were not okay, display error ### ### message and redisplay form ### if
(@sizeof($blanks) > 0 or @sizeof($formats) > 0) #54 { if (@size($blanks) >
0) { echo "<b>You didn't fill in one or more required fields. You
must enter:</b><br>"; foreach($blanks as $field => $value) { echo
" {$labels[$field]}<br>"; } } if (@sizeof($formats) > 0) {
echo "<b>One or more fields have information that appears to be
incorrect. Correct the format for:</b><br>"; foreach($formats as $field
=> $value) { echo " {$labels[$field]}<br>"; } } echo
"<hr>"; include("adressForm.inc"); } else { ### If no errors in the
form, display the ### ### name and address submitted by user ### echo
"<html><head><title>Name and Address </title></head><body>\n";
foreach($_POST as $field=>$value) { if($field != "Submit") { echo
"{$labels[$field]} $value<br>\n"; } } echo "</body></html>"; } } ?>
_________________________________________________________________
Probeer Live.com: jouw leven online met nieuws, sport, weer en nog veel meer.
http://www.live.com/getstarted<?php
/* Script name: addressForm.inc
* Description: Script displays a form.
*/
echo "<html>
<head><title>Customer Address</title></head>
<body>";
echo "<p align='center'>
<form action='validateForm.php' method='POST'>
<table width='95%' border='0' cellspacing='0'
cellpadding='2'\n";
foreach($labels as $field=>$value)
{
if(isset($_POST[$field]))
{
$value = $_POST[$field];
}
else
{
$value = "";
}
echo "<tr><td align='right'>{$labels[$field]}</br></td>
<td><input type='text' name'$field' size='65'
maxlength='65'
value='$value'> </td> </tr>";
}
echo " </table>
<div align='center'>
<p><input type='Submit' name='Submit'
value='Submit Address'></p></div>
</form>";
?>
</body></html><?php
/* Script name: info.inc
* Description: creates an array of labels for use in a
* form.
*/
$labels = array( "firstName"=> "First Name:",
"midName"=>"Middle Name:",
"lastName"=>"Last Name:",
"street"=>"Street Address:",
"city"=>"City:",
"state"=>"State:",
"zipcode"=>"Zipcode:");
?>
--- End Message ---
--- Begin Message ---
On Monday 25 December 2006 13:35, Geert T wrote:
> Hi,
>
> I have made some script that process the users input, and validates the
> input and sends it back. But it doesn't work very well, in fact it doesn't
> work at all. I am only able to see and input my name and such in the html
> form, but the php part doesn't do it's job. I have looked over the scripts
> thousands of times, but couldn't find the problem, really.
>
> Here is the script plus 2 .inc files;
>
> Hoping for some replies and answers,
> Thanks in advance!
>
> PS: if this script is a bit messy to read, I have included them in this
> mail seperately.
>
I cannot get 3rd script. And this one may solve your problem in address form
and info.inc..
<?php
$labels = array( "firstName"=> "First Name:",
"midName"=>"Middle Name:",
"lastName"=>"Last Name:",
"street"=>"Street Address:",
"city"=>"City:",
"state"=>"State:",
"zipcode"=>"Zipcode:");
$strLoop = '';
$intSize = sizeof($labels);
$arrKeys = arrayKeys($labels);
for($l=0;$l<$intSize;$l++)
{
$value = '';
if(isset($_REQUEST[$labels[$arrKeys[$l]]]))
{
$value = $_REQUEST[$labels[$arrKeys[$l]]];
}
$strLoop.=
" <tr>
<td align='right'>
".$labels[$arrKeys[$l]]."<br/>
</td>
<td>
<input type='text'
name='".$arrKeys[$l]."' size='65' maxlength='65'
value='".$value."' />
</td>
</tr>\n";
}
$strPage =
"<html>
<head>
<title>
Customer Address
</title>
</head>
<body>
<p align='center'>
<form action='validateForm.php' method='POST'>
<table width='95%' border='0' cellspacing='0'
cellpadding='2'>
".$strLoop."
<tr>
<td align='center'>
<input type='Submit' name='Submit'
value='Submit Address' />
</td>
</tr>
</table>
</form>
</p>
</body>
</html>\n";
echo $strPage;
?>
validateForm.php
May Look like this
<?php
$intSize = sizeof($_REQUEST);
$arrKeys = array_keys($_REQUEST)
// Or you may use $labels array again
if($intSize > 0)
{
for($r=0;$r<$intSize;$r++)
{
// do some global check for all $_REQUEST elements
// then do some conditional
switch ($_REQUEST[$arrKeys[$r]])
{
case "firstName":
//do Someting
break;
....
}
}
}
?>
Regards
Sancar
--- End Message ---
--- Begin Message ---
# [EMAIL PROTECTED] / 2006-12-24 18:11:03 -0800:
> function display($list, $in, $out, $save, $req, $x)
> {
> for($i = 0; $i < count($in); $i++)
> {$j = $i + 1;
> // two sets of links displayed instead of one
> for($i = 0; $i < count($out); $i++)
> {$j = $i + 1;
> // two sets of links displayed instead of one
> for($i = 0; $i < count($save); $i++)
> {$j = $i + 1;
> // two sets of links displayed instead of one
> for($i = 0; $i < count($req); $i++)
> {$j = $i + 1;
> // two sets of links displayed instead of one
> The print lines above are supposed to produce a list of links to files.
> In the web display I get duplicate sets of links which seems to mean
> that the loops in the function are running twice, and in one instance
> three times instead of once.
Look at the variable names you use for iteration.
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
--- End Message ---
--- Begin Message ---
On Dec 25, 2006, at 7:21 AM, Roman Neuhauser wrote:
# [EMAIL PROTECTED] / 2006-12-24 18:11:03 -0800:
function display($list, $in, $out, $save, $req, $x)
{
for($i = 0; $i < count($in); $i++)
{$j = $i + 1;
// two sets of links displayed instead of one
for($i = 0; $i < count($out); $i++)
{$j = $i + 1;
// two sets of links displayed instead of one
for($i = 0; $i < count($save); $i++)
{$j = $i + 1;
// two sets of links displayed instead of one
for($i = 0; $i < count($req); $i++)
{$j = $i + 1;
// two sets of links displayed instead of one
The print lines above are supposed to produce a list of links to
files.
In the web display I get duplicate sets of links which seems to mean
that the loops in the function are running twice, and in one instance
three times instead of once.
Look at the variable names you use for iteration.
Thanks, Usually, when a variable name like $i is used and then
reset to 0 in the next loop it does not matter. But I solved the
problem and posted the solution. I also solved the regex
problem. There was an extra \n sneaking into the test pattern
so I could not get a match. I am not sure where the extra \n is
coming from.
It looks like I didn't post the solution after all:
Update:
I solved the double loops problem with this code change:
function display($list, $a, $x)
{
for($i = 0; $i < count($a); $i++)
{$j = $i + 1;
print "<a
href=\"steps.php?list=$list&next=$j&x=$x\">$j</a><br><br>\n";
};
}
and:
if($list || $current)
{
switch($list)
{
case 'in':
display($list, $in, $x);
break;
case 'out':
display($list, $out, $x);
break;
case 'save':
display($list, $save, $x);
break;
case 'req':
display($list, $req, $x);
break;
}
}
Apparently what was happening was that the code running under 5.1.2
was trying to process all the arrays that had values in spite of the
switch
statement in the original display() function. If the was an $in array
the
switch would process that for the $list value being 'in' but since
there
was also a save value, the switch tried to process it also, even though
'save' wasn't the $list value. I found it would do this for all arrays
that
had values. So if three had values the loop selected loop would run
three times.
Could this be a bonafide bug?
JK
--- End Message ---