Re: [PHP-DB] Escaping

2001-07-12 Thread Roger Ramirez

When they click on the link what is happening?  Is it doing a query in the
database for all users with that name?  If so you may want to do a
str_replace('','\','customer_name') before your query.  Basically you
just want to add the \ before the ampersand.  I haven't tried this but it
SHOULD work.

Roger

On Thu, 12 Jul 2001, Rankin, Randy wrote:

 Hello,
 
 I have a table in a MySQL DB (RH Linux/Apache) with a field called
 customer_name. Some of the customer names have an ampersand in them (ie; X 
 X Supply). I am performing a select statement on this table to create a
 sales summary with customer name and total sales.
 
 This works fine; however, I am also creating a dynamic link on the customer
 name so that the user can click on it to get a detailed report of sales to
 that customer. This works great EXCEPT for the customers with ampersands in
 thier names. The result of clicking on these customers indicates a No
 Records found for X where X is the letter immediately preceding the
 ampersand.
 
 Does anyone know how to get around this?
 
 TIA, 
 
 Randy Rankin
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Paging help needed :-(

2001-07-12 Thread Roger Ramirez

Here is some code that I like to use.  I mix real code and psuedo code cause
I'm more used to just using the db class from PHP Lib.

First get a count of how many records there are.

$sql = SELECT count(*) as c FROM users;
Then read that count into variable $count.

Declare a variable which will contain the number of records per page, this
is a really good idea cause if that number changes later you just have to
change one variable instead of hunting down every instance of that number.

$records_per_page = 10;

Next figure out how many pages you'll have.

$total_pages = ceil( $count / $records_per_page );

This just sets up a page variable which will be past in a next and prev
link.  The first link to this page may not actually have $page so this just
sets it up.
if ( !isset($page) ) { $page = 1; }

I like to setup a little navigation that has First | Prev | Next | Last on
the page with each word being a link or not depending on what page you are
on.  To do this I use the following piece of code.

# this will set up the First | Prev |  part of our navigation.
if ( $page == 1 ) {
# if we are on the first page then First and Prev
# should not be links.
$naviagation = font color=\#66\First/font | font
color=\#66\Prev/font | ;
} else {
# we are not on page one so First and Prev can
# be links
$prev_page = $page - 1;
$navigation = a href=\your_page.php?page=1\First/a | a
href=\your_page.php?page=$prevpage\Prev/a | ;
}

# this part will set up the rest of our navigation Next | Last
if ( $page == $total_pages ) {
# we are on the last page so Next and Last
# should not be links
$navigation .= font color=\#66\Next/font | font
color=#66Last/font;
} else {
# we are not on the last page so Next and Last
# can be links
$next_page = $page + 1;
$navigation .= a href=\your_page.php?page=$next_page\Next/a | a
href=\your_page.php?page=$total_pages\Last/a;
}

With your navigation built you can just echo that out any where you want it
to appear.

The final thing to do is your actual query, but first we have to figure out
what the offset will be.

$offset = ( $page - 1 ) * $total_pages;
$sql = SELECT id, email, name, subject, url, image2, comments, dat
FROM users
ORDER BY id DESC
LIMIT $offset,$records_per_page;

And that's it?  Simple eh?

You may also want to put out something like: echo $page of $total_pages;

Enjoy.

- Original Message -
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, July 12, 2001 3:49 AM
Subject: [PHP-DB] Paging help needed :-(


Hi there Everyone,

I currently have a dedicated Apache server with PHP 4.06, MySQL etc ..
installed and running fine.  Below is alittle peice of code that I would
love an answer to:

?php

$connection = mysql_connect(Localhost,username!!!,password!!!) or
die(Couldn't make a connection.);

$db = mysql_select_db(planet, $connection)
 or die(Couldn't select database.);

$sql = SELECT id, email, name, subject, url, image2, comments, dat
FROM users
ORDER BY id DESC;

$sql_result = mysql_query($sql,$connection)
 or die(Couldn't execute query.);

   ?

?

while ($row = mysql_fetch_array($sql_result)) {
 $email = $row[email];
 $name = $row[name];
 $subject = $row[subject];
 $url = $row[url];
 $image2 = $row[image2];
 $comments = $row[comments];
 $dat = $row[dat];
$comments=nl2br($comments);
include(censorguestbook.php);

$ip = getenv (REMOTE_ADDR);

?

then all the HTML and display bits (Example at www.planetoxygene.com in the
guestbook).

?

}

mysql_free_result($sql_result);
mysql_close($connection);

?

Now my question is, how do I do paging in PHP?  I need to display 10 entries
per page, and be able to go back and forth with them.  I'm relatively new to
PHP so I would be really grateful for any advice.

Thanks everyone, I appreciate it.

Chris Payne
www.planetoxygene.com




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] finding out the result of an INSERT

2001-07-10 Thread Roger Ramirez

http://php.net/manual/en/function.mysql-insert-id.php

 from the link above 
Warning:
mysql_insert_id() converts the return type of the native MySQL C API
function mysql_insert_id() to a type of long. If your AUTO_INCREMENT column
has a column type of BIGINT, the value returned by mysql_insert_id() will be
incorrect. Instead, use the internal MySQL SQL function LAST_INSERT_ID().


- Original Message -
From: Cable, Christian [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, July 10, 2001 6:51 AM
Subject: [PHP-DB] finding out the result of an INSERT


 Hi,

 this might be a stupid question but it's got me stumped today

 My setup: php, mysql, apache etc

 I'm inserting a record into a table that's got a primary key which is auto
 incrementing ..

 +---+---+--+-+-++
 | Field | Type  | Null | Key | Default | Extra  |
 +---+---+--+-+-++
 | message_id| int(11)   |  | PRI | NULL| auto_increment |
 | message_text  | mediumtext| YES  | | NULL||
 | topic_id  | int(11)   | YES  | | NULL||
 | user_id   | int(11)   | YES  | | NULL||
 | message_title | varchar(50)   | YES  | | NULL||
 | message_time  | timestamp(14) | YES  | | NULL||
 | parent_id | int(11)   | YES  | | NULL||
 | thread_id | int(11)   | YES  | | NULL||
 +---+---+--+-+-++

 by doing

 $sql = INSERT INTO messagetable(user_id, message_title,
message_text,topic_id,
 thread_id, parent_id) VALUES
 ('$userid','$subject','$comment','$topic_id','$thread_id','$parent_id');
 mysql_query($sql);

 which works fine BUT is there any way of finding out the message_id of the
 record I just inserted ?

 with thanks

 Christian


 Christian Cable
 ICT Assistant
 Careers Service; Lancaster University
 Tel: (01524) 594072  Fax: (01524) 592072
 http://www.lancs.ac.uk/staff/cable/



 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Suggest Table Structure

2001-07-05 Thread Roger Ramirez

Make a table for pictures.  Something simple that has an id and your picture
then in your article table you just change your picture field to your
picture id field.  You may want to do the same thing with category and any
other field if you notice that the article belongs in multiple categories.

- Original Message -
From: kachaloo [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, July 05, 2001 5:00 AM
Subject: [PHP-DB] Suggest Table Structure


 Hi guys,
 I am making a table which will store articles for a site
 and the feilds are :

 ID int(6) NOT NULL auto_increment,
 CATEORY varchar(10) NOT NULL DEFAULT 'EVENTS' ,
 HEADING varchar(30) NOT NULL DEFAULT '' ,
 BODY longblob ,
 PICTURE longblob ,
 KEYWORD varchar(30) NOT NULL DEFAULT '' ,
 FILENAME varchar(50) ,
 FILESIZE varchar(50) ,
 FILETYPE varchar(50) ,
 PRIMARY KEY (ID),
 UNIQUE ID (ID)


 But now I noticed some of the articles will have more than one
 picture... so how do I structure my table ?

 Thanks in advance,
 Vishal

 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]