php-general Digest 30 Mar 2003 18:57:24 -0000 Issue 1969

Topics (messages 141628 through 141646):

Re: Adding a URL
        141628 by: Don Read
        141629 by: Hugh Danaher

Question
        141630 by: Marius
        141631 by: Kevin Waterson
        141632 by: Julien Wadin
        141633 by: Marius
        141636 by: Don Read
        141637 by: skate
        141638 by: Don Read
        141641 by: skate

Re: upload question
        141634 by: Dan Rossi

Re: Theme selector?
        141635 by: Lars Tvedt

PHP and Visual Studio.Net
        141639 by: Ulrik
        141642 by: Steven Kallstrom

Re: preg_replace_callback and brackets
        141640 by: Marek Kilimajer

Ereg question
        141643 by: Beauford

Sessions and iframes (or frames)?
        141644 by: Tiago Simões
        141645 by: John W. Holmes

accessing result-set with associative array
        141646 by: anders thoresson

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 ---
On 30-Mar-2003 Scott Thompson wrote:
> Hi,
> 
> I am using the following code to query a database and build an HTML
> table.
> 

<snip>

>      /* Printing results in HTML */
>      print "<table>\n";
>      while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {

$line['email'] =
 '<A HREF="mailto:' .$line['email'] .'">' .$line['email'].'</A>';

>          print "\t<tr>\n";
>          foreach ($line as $col_value) {
>           print "\t\t<td>$col_value</td>\n";
>          }
>          print "\t</tr>\n";

// how about this ?

 echo "\n<tr><td>", implode('</td><td>', $line), '</td></tr>'; 

>      }
>      print "</table>\n";

<snip> 

> What I want (and can't figure out) is how to have each email address 
> have a URL (i.e. mailto:[EMAIL PROTECTED]).
> 
> I'm fairly new to PHP, I hope this question made some sense.
> 
> Suggestions?
> 

Regards,
-- 
Don Read                                       [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

--- End Message ---
--- Begin Message ---
Scott,
try changing:
  print "\t\t<td>$col_value</td>\n";
to:
  print "\t\t<td><a href=mailto:".$col_value.";>$col_value</a></td>\n";
Hope this helps.
Hugh

----- Original Message -----
From: "Scott Thompson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, March 29, 2003 8:53 PM
Subject: [PHP] Adding a URL


> Hi,
>
> I am using the following code to query a database and build an HTML table.
>
> <html>
>   <head>
>    <title>SQL Connect</title>
>   </head>
>
>   <body>
>    <?php
>      /* Connecting, selecting database */
>      $link = mysql_connect("localhost", "root", "")
>          or die("Could not connect");
>      //print "Connected successfully";
>      mysql_select_db("irvington") or die("Could not select database");
>
>      /* Performing SQL query */
>      $query = "SELECT * FROM staff";
>      $result = mysql_query($query) or die("Query failed");
>
>      /* Printing results in HTML */
>      print "<table>\n";
>      while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
>          print "\t<tr>\n";
>          foreach ($line as $col_value) {
>     print "\t\t<td>$col_value</td>\n";
>          }
>          print "\t</tr>\n";
>      }
>      print "</table>\n";
>
>      /* Free resultset */
>      mysql_free_result($result);
>
>      /* Closing connection */
>      mysql_close($link);
>    ?>
>
>   </body>
> </html>
>
>
> So far so good...
>
> The SQL query returns this:
> mysql> select * from staff;
> +----------------+------------------------------+------------------+
> | name           | email                        | subject          |
> +----------------+------------------------------+------------------+
> | Scott Thompson | [EMAIL PROTECTED] | Volunteer        |
> | <sanitized>    | <sanitized>                  | Computer Science |
> | Some Teacher   | [EMAIL PROTECTED]   | some subject     |
> +----------------+------------------------------+------------------+
> 3 rows in set (0.00 sec)
>
> mysql>
>
> The above is also essentialy what you see in your browser (sans headers).
>
> So far so good...
>
> What I want (and can't figure out) is how to have each email address
> have a URL (i.e. mailto:[EMAIL PROTECTED]).
>
> I'm fairly new to PHP, I hope this question made some sense.
>
> Suggestions?
>
> ~Scott
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


--- End Message ---
--- Begin Message ---
 <?php
 $list = array ('Ba-na-na', 'Ber-ry');
 echo "<a href=\"index.php?fruit={$list['0']}\">";
 echo $list['0'];
 echo "</a>";
 ?>
 how i can get "Ba-na-na" in url and "Banana" or "Ba na na" in echo ?

-- 
 Marius
 [EMAIL PROTECTED]



--- End Message ---
--- Begin Message ---
This one time, at band camp,
Marius <[EMAIL PROTECTED]> wrote:

>  <?php
>  $list = array ('Ba-na-na', 'Ber-ry');
>  echo "<a href=\"index.php?fruit={$list['0']}\">";
>  echo $list['0'];
>  echo "</a>";
>  ?>
>  how i can get "Ba-na-na" in url and "Banana" or "Ba na na" in echo ?

$list = array('Ba-na-na', 'Ber-ry');

echo '<a href="\index.php?fruit='.$list[0].'">'.str_replace('-','',$list[0]).'</a>';

Kevin
-- 
 ______                              
(_____ \                             
 _____) )  ____   ____   ____   ____ 
|  ____/  / _  ) / _  | / ___) / _  )
| |      ( (/ / ( ( | |( (___ ( (/ / 
|_|       \____) \_||_| \____) \____)
Kevin Waterson
Port Macquarie, Australia

--- End Message ---
--- Begin Message ---
just do that :

to have Banana :
$a = ereg_replace("-","",$list[0]);

to have Ba na na
$b = ereg_replace("-"," ",$list[0]);

Bye

__________________________________________________________________
WADIN JULIEN
URL : www.campinfm.be.tf



-----Message d'origine-----
De : Marius [mailto:[EMAIL PROTECTED]
Envoyé : dimanche 30 mars 2003 11:44
À : [EMAIL PROTECTED]
Objet : [PHP] Question


 <?php
 $list = array ('Ba-na-na', 'Ber-ry');
 echo "<a href=\"index.php?fruit={$list['0']}\">";
 echo $list['0'];
 echo "</a>";
 ?>
 how i can get "Ba-na-na" in url and "Banana" or "Ba na na" in echo ?

--
 Marius
 [EMAIL PROTECTED]



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



--- End Message ---
--- Begin Message ---
 <?php
 $i = 0;
 $list = array('Banana', 'Strawberry', 'Apple', 'Cherry');
 echo $list[$i];
 $i = $i+1;
 ?>

 how to do that 2 of key echoes in first table colum and other 2 in
 second colum?

-- 
 Marius
 [EMAIL PROTECTED]



--- End Message ---
--- Begin Message ---
On 30-Mar-2003 Marius wrote:
>  <?php
>  $i = 0;
>  $list = array('Banana', 'Strawberry', 'Apple', 'Cherry');
>  echo $list[$i];
>  $i = $i+1;
>  ?>
> 
>  how to do that 2 of key echoes in first table colum and other 2 in
>  second colum?
> 

Method 1:

$i=0;
echo '<tr><td>
foreach($list as $v) { 

    echo $v, '<br>';
    if (! (++$i % 2))
        echo '</td>';
        if ($i < count($list))
             echo '<td>';
    }
}
echo '</tr>';


Method 2:

echo '<tr>';
unset($blk);
foreach($list as $v) {
    if (count($blk) >= 2) {
        echo '<td>', implode('<br>', $blk), '</td>';
        unset($blk);
    }
    $blk[] = $v;
}

if (count($blk) )
     echo '<td>', implode('<br>', $blk), '</td>';
echo '</tr>';


Regards,
-- 
Don Read                                       [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

--- End Message ---
--- Begin Message ---
excuse me for being dumb, but can you explain this line for me?

if (! (++$i % 2))

i've done scripts like this before, but never used anything like this? but
then i never was a great coder :)

thanks

----- Original Message -----
From: "Don Read" <[EMAIL PROTECTED]>
To: "Marius" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Sunday, March 30, 2003 1:54 PM
Subject: RE: [PHP] question


>
> On 30-Mar-2003 Marius wrote:
> >  <?php
> >  $i = 0;
> >  $list = array('Banana', 'Strawberry', 'Apple', 'Cherry');
> >  echo $list[$i];
> >  $i = $i+1;
> >  ?>
> >
> >  how to do that 2 of key echoes in first table colum and other 2 in
> >  second colum?
> >
>
> Method 1:
>
> $i=0;
> echo '<tr><td>
> foreach($list as $v) {
>
>     echo $v, '<br>';
>     if (! (++$i % 2))
>         echo '</td>';
>         if ($i < count($list))
>              echo '<td>';
>     }
> }
> echo '</tr>';
>
>
> Method 2:
>
> echo '<tr>';
> unset($blk);
> foreach($list as $v) {
>     if (count($blk) >= 2) {
>         echo '<td>', implode('<br>', $blk), '</td>';
>         unset($blk);
>     }
>     $blk[] = $v;
> }
> 
> if (count($blk) )
>      echo '<td>', implode('<br>', $blk), '</td>';
> echo '</tr>';
>
>
> Regards,
> --
> Don Read                                       [EMAIL PROTECTED]
> -- It's always darkest before the dawn. So if you are going to
>    steal the neighbor's newspaper, that's the time to do it.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>



--- End Message ---
--- Begin Message ---
On 30-Mar-2003 skate wrote:
> excuse me for being dumb, but can you explain this line for me?
> 
> if (! (++$i % 2))
> 

If $i is evenly divisible by 2 then ($i % 2) evaluates to 0 or (false).
The (! ($i % 2)) inverts the meaning to (true) so the statements within
the if block are executed.

The ++$i bit --well it's a handy spot to increment $i, and the pre-increment
notation gets around the case when $i == 0.

Regards,
-- 
Don Read                                       [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

--- End Message ---
--- Begin Message ---
ahkay, makes perfect sense now :)

thanks
----- Original Message -----
From: "Don Read" <[EMAIL PROTECTED]>
To: "skate" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Sunday, March 30, 2003 2:19 PM
Subject: Re: [PHP] question


>
> On 30-Mar-2003 skate wrote:
> > excuse me for being dumb, but can you explain this line for me?
> >
> > if (! (++$i % 2))
> >
>
> If $i is evenly divisible by 2 then ($i % 2) evaluates to 0 or (false).
> The (! ($i % 2)) inverts the meaning to (true) so the statements within
> the if block are executed.
>
> The ++$i bit --well it's a handy spot to increment $i, and the
pre-increment
> notation gets around the case when $i == 0.
>
> Regards,
> --
> Don Read                                       [EMAIL PROTECTED]
> -- It's always darkest before the dawn. So if you are going to
>    steal the neighbor's newspaper, that's the time to do it.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--- End Message ---
--- Begin Message ---
err its "open with" actually

-----Original Message-----
From: Hugh Danaher [mailto:[EMAIL PROTECTED]
Sent: Sunday, March 30, 2003 2:04 PM
To: Anthony Ritter
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] upload question


Sounds like a Windows configuration issue and not a php issue.  There's an
'open using' (or some such) option buried in the windows file menu that will
let you change this.
Hugh
----- Original Message -----
From: "Anthony Ritter" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, March 29, 2003 7:12 PM
Subject: [PHP] upload question


> Greetings all,
> Using PHP 4.1.1 / Apache Server / MS Win 98 / IE 5.5
>
> The following script is from Julie Meloni's book PHP Fast and Easy on page
> 170-174.
>
> The first part is an html form in which the user browses and chooses a
file
> to be upoloaded to the server.
>
> The script works fine in that when I chose a file and hit submit it, the
> file ends up in:
>
> C:\apache\htdocs
>
> However, in the book, in the last illustration, she explains:
>
> "Just to be sure, use the File/Open Page menu item in your _browser_ to
> navigate through your filesystem and find the file that you just
uploaded."
>
> The illustration shows the .jpg file _within_ the browser screen on the
> upper left hand side.
>
> When I follow those steps and hit file / open, my paint program takes over
> and opens the uploaded .jpg file and the browser interface of MS IE 5.5 is
> gone.
>
> Any advice would be appreciated.
> Thank you.
>
> Tony Ritter
> .......................................................................
>
> // html form
> </head>
> <body>
> <form action="upload.php" method="post" enctype="multipart/form-data">
> <p>
> File to upload:
> <input type="file" name="thefile" size="30">
> </p>
> <p>
> <input type="submit" name="submit" value="Upload File">
> </p>
> </form>
> </body>
> </html>
>
>
> // .php script called  upload.php
> <?
> if ($thefile != "")
>  {
>   copy("$thefile","C:\\apache\\htdocs\\$thefile_name")or die("Could not
copy
> the file.");
>  }
> else
>  {
>   echo "No file to upload.";
>  }
> ?>
> <html>
> <head>
> </head>
> <body>
> <p>
> You sent:
> <? echo "$thefile_name"; ?>, a <? echo "$thefile_size"; ?> byte file with
a
> mime type of <? echo "$thefile_type" ; ?>.
> </p>
> </body>
> </html>
>
>
>
>
> --
> 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 ---
i would have used templates: heres one http://smarty.php.net
"Liam Gibbs" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> > Hello, can anyone help me with a php theme selector? I want it like when
> > the seletect a theme ?theme=green that it will go into a directory and
> > load green.php or somthing like that please help. Thankyou
>
> I'd store your themes in stylesheets instead.
>



--- End Message ---
--- Begin Message ---
Hello,

maybe somebody can help me. I am involved in a web project for the first
time now and I'd like to keep my current development environment, Visual
Studio.Net. Is there any way to incorporate PHP Syntax highlighting into
Visual Studio.Net or Visual Studio 6.0??? In 6.0, I can choose to handle PHP
files like C++ files, which helps at least a bit, but I haven't found a
similar function in VS.Net

Any help is greatly appreciated!

thanx

ulrik


--- End Message ---
--- Begin Message ---
Ulrik,

        For PHP editing in Visual Studio .NET...

        http://www.quake-au.net/php/php_and_vsdotnet.htm

SJK



--- End Message ---
--- Begin Message --- Maybe you should use

/\b/

word boundary

instead of all the or's

Joshua Moore-Oliva wrote:

I'm kind of confused right now... when I call preg_replace_callback with a regular expression with brackets, sometimes I get an array back with multiple elements like

array(3) {
 [0]=>
 string(19) "http://www.aol.com
"
 [1]=>
 string(0) ""
 [2]=>
 string(19) "http://www.aol.com
"
}

and I have no idea why... Why does the middle one have nothing in it? the regular expression was

$dumb_body = preg_replace_callback ( '/'
//Case spaceURLspace
. '([\s]http:\/\/[^\s]+[\s])'
. '|'
//Case URLspace
. '(^http:\/\/[^\s]+[\s])'
. '|'
//Case spaceURL
. '([\s]http:\/\/[^\s]+$)'
. '|'
//Case URL
. '(^http:\/\/[^\s]+$)'
. '/i'
, array( &$this, "storeUrlCallback" ), $dumb_body );


I am very confused at the point of the array in this function period... can anyone help?

Josh.





--- End Message ---
--- Begin Message ---
I am using ereg to validate the format of a date entry (mm/dd/yy), but if
the year ends in a 0, it is being stripped and as such produces an error. So
1990 would be 199.  The dob is being inputted by a form....

Here is my code:

if (!ereg("^([0-9]{2})/([0-9]{2})/([0-9]{4})$", $formsave["dob"], $parts)) {
 $error["dob"] = "*"; $message["dob"] = "Invalid date format!";
 $dob = " \"$parts[3]-$parts[2]-$parts[1]\"";
}

Thanks



--- End Message ---
--- Begin Message ---
Hello.


I built this site using using different iframes: one for a login, other for
a forum, another for a voting poll, etc...

I was wondering what is the best way to ensure that you could only post a
topic in the forum, or vote if you had already logged in.

I'm somewhat familiar with the $_session global variable, but only if the
code happens in the same page. How can you check, from another frame, that
user is logged?

Thanks in advance...
Tiago Simões



--- End Message ---
--- Begin Message ---
> I built this site using using different iframes: one for a login,
other
> for
> a forum, another for a voting poll, etc...
> 
> I was wondering what is the best way to ensure that you could only
post a
> topic in the forum, or vote if you had already logged in.
> 
> I'm somewhat familiar with the $_session global variable, but only if
the
> code happens in the same page. How can you check, from another frame,
that
> user is logged?

That "other frame" would have to refresh and check the $_SESSION just
like any other page. Each frame is it's own request, so in order for a
frame to do anything with PHP, it will need to be refreshed or something
requested within the frame.

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



--- End Message ---
--- Begin Message --- Hi,

I've the query "SELECT albums.name, albums.albumid, accessrights.albumid, accessrights.userid FROM albums, accessrights WHERE accessrights.userid = '$id' AND albums.albumid = accessrights.albumid".

It works allright. Using the result in a html <SELECT>-tag this way works:

        while($row = mysql_fetch_array($result))        {
                echo("<OPTION VALUE=\"$row[1]\"> $row[0]");
        }

But if I tries the following line, the script fails:

echo("<OPTION VALUE=\"$row['albums.albumid']\"> $row['albums.name']");

with the notice:
Undefined index: 'albums.albumid' in <b>c:\web\thoresson.net\include\user_functions.php</b> on line <b>24</b>


I've been trying to learn PHP for three months now, but tonight was the first time I sat down with my project for two week, so I'm sorry if I'm bothering you with something obvious that I've just forgotten. :)

But I need to know: What am I doing wrong?

Best regards.

--
anders thoresson

--- End Message ---

Reply via email to