Re: [PHP-DB] Display records on form

2005-01-05 Thread Jochem Maas
I'm resending this email as it does seems to have made its way onto the 
list (as far as I can see) - apologies if this is a double post.

anyone else interested in recieving the pagination function I mention 
below can mail me offlist.

here is the original reply:
David Ziggy Lubowa wrote:


first of all , let me apologize for the top post, second let me apologize for 
not giving more detail.  The main problem is basically pagination , i have 
failed to add pagination code to my own code simply because it is not as 
simple as i thought.  Considering i am a begginer in PHP , i must give myself 
some credit for reaching where i am ,  as for code snippet here goes,

...
pagination is fairly simple once you have done it a few times, It took
me ages to get my head round too.

$link = mysql_connect(localhost, me,me2);
mysql_select_db(ip, $link);
$qry = mysql_query(SELECT * FROM IP_Addresses where free like '%.
$_GET['q'].%', $link);
I think you should use the $trimmed var here iso $_GET['q'], also you
should make sure that any single quotes in this string are escaped
properly (otherwise they will break your query).
to do pagination you have to combine pagination links (that are used to
propigate the 'page number' and current query parameter) by adding:
LIMIT $i, 50
to the end of your query, where $i is a multiple of 50 (lets assume you
wish to show 50 rows per page) - $i would be equal to zero for the first
page. the value of $i has to be propigated through the pagination links
- the function I sent to you offlist has a parameter to handle this.
BTW the function I sent you returns HTML (links!) which you need to
include with your output to allow users to select different pages. Also
note that the second argument to the function is not actually used - its
merely there so that the function is also usable as a Smarty plugin.
other than using the output from the function I sent you and making use
of LIMIT clause the rest of you code does not need to change.
TIP: try to seperate processing logic from your output, i.e. breaking in
and out of PHP the whole time (using ?php ?) makes you code hard to
read/maintain. to start with you could create all ness. vars containing
dynamic content at the top of your script and then at the bottom output
the HTML (maybe even by including a file, that file would contain just
the HTML and enough PHP to output the dynamic data, the file would
assume all ness. data vars are set).
?
table border=1 width=100%tr?php
if (mysql_num_rows($qry)==0 ) {
print  Oops No records found ;
?
br
a href=http://localhost/ipsearch2.html;Back/a
/br
?
exit();
}
if (mysql_num_rows($qry)  0) {
   for ($i = 0; $imysql_num_fields($qry); $i++) {
   echo td align=centerstrong . mysql_field_name($qry, $i) . 
/td;
}
}
good for you for taking the generic route rather than hard coding you
fieldnames!
?
/tr?php
if (mysql_num_rows($qry)  0) {
   for ($j = 0; $jmysql_num_rows($qry); $j++) {
   ?tr?php
   for ($k = 0; $kmysql_num_fields($qry); $k++) {
   echo td align=center . mysql_result($qry,$j, $k) . /td;
   }
   ?/tr?php
   }
}
?
/table
br
br
a href=http://localhost/index.html;Main Page/a
br
br
a href=http://localhost/ipsearch2.html;IP Address Search/a/br/br
/br
/br
/body
/html
[/snip]
i had posted some time back that i have problems with pagination and got alot 
of help , but the problem is i have never known how to put the code together 
with what i have .. any help is appreciated...

cheers

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


Re: [PHP-DB] Display records on form

2005-01-04 Thread David Ziggy Lubowa
On Tuesday 04 January 2005 10:10, David Ziggy Lubowa wrote:
 Hey guys ,

  I was wondering , i have 16 records within a table in my Database , i have
 managed to have a form which can add and modify the records. My only
 problem is how i can display on a form when i search. Can someone give me
 heads up on how i can code this in php, to display the records in a tabular
 manner when i search.

sorry i meant 16 fields  not records : )

 Any help is highly appreciated.


 cheers

 -Z

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



Re: [PHP-DB] Display records on form

2005-01-04 Thread Jochem Maas
David Ziggy Lubowa wrote:
On Tuesday 04 January 2005 10:10, David Ziggy Lubowa wrote:
Hey guys ,
I was wondering , i have 16 records within a table in my Database , i have
managed to have a form which can add and modify the records. My only
problem is how i can display on a form when i search. Can someone give me
heads up on how i can code this in php, to display the records in a tabular
manner when i search.
how does somebody manage to create a working script to insert/update 
data in a table and not be able to figure out how to output a simple 
HTML table listing the current records?
I mean, do you want us to teach you how to write PHP? (My rate is 
40euros/hour)

--
Sorry David but your email shows little to no effort on your part to:
a, define you problem succinctly
b, show context (e.g. code,SQL snippets)
c, show that you have made a decent effort to work the problem.
given those facts you can consider yourself lucky to recieve any replies 
at all.

ANYWAY... seeing as I'm bitchin' at ya I might as well give you a small 
clue

the process, roughly speaking is:
1. do a SQL select query. (e.g. SELECT id,name FROM mytable)
2. loop thru the result, for each row output some HTML for a table row
e.g.
echo '
tr
tda href=/edit.php?id='.$row['id'].'edit/td
td'.$row['id'].'/td
td'.$row['name'].'/td
/tr'
3. don't forget to add begin- and ending TABLE tags.
try googling 'display a MYSQL result set with PHP':
I came up with:
http://juicystudio.com/tutorial/php/mysql.asp
(which is pretty funny cos the guy wrote a tutorial on mysql/php on an 
ASP based site!!)


sorry i meant 16 fields  not records : )
whether you tables has 16 rows or fields seems to me to be completely 
irrelevant.


Any help is highly appreciated.
cheers
-Z

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


Re: [PHP-DB] Display records on form

2005-01-04 Thread David Ziggy Lubowa





first of all , let me apologize for the top post, second let me apologize for 
not giving more detail.  The main problem is basically pagination , i have 
failed to add pagination code to my own code simply because it is not as 
simple as i thought.  Considering i am a begginer in PHP , i must give myself 
some credit for reaching where i am ,  as for code snippet here goes,


[snip]




html
titleIP Addresses/title
body

?php


  // Get the search variable from URL

  $var = @$_GET['q'] ;
  $trimmed = trim($var); //trim whitespace from the stored variable

// check for an empty string and display a message.
if ($trimmed == )
  {
  echo pPlease enter a search.../p;
  exit;
  }

// check for a search parameter
if (!isset($var))
  {
  echo pWe dont seem to have a search parameter!/p;
  exit;
  }




$link = mysql_connect(localhost, me,me2);
mysql_select_db(ip, $link);
$qry = mysql_query(SELECT * FROM IP_Addresses where free like '%.
$_GET['q'].%', $link);

?
table border=1 width=100%tr?php

if (mysql_num_rows($qry)==0 ) {

print  Oops No records found ;
?
br
a href=http://localhost/ipsearch2.html;Back/a
/br
?
exit();
}
if (mysql_num_rows($qry)  0) {
   for ($i = 0; $imysql_num_fields($qry); $i++) {
   echo td align=centerstrong . mysql_field_name($qry, $i) . 
/td;
}
}

?

/tr?php

if (mysql_num_rows($qry)  0) {
   for ($j = 0; $jmysql_num_rows($qry); $j++) {

   ?tr?php

   for ($k = 0; $kmysql_num_fields($qry); $k++) {
   echo td align=center . mysql_result($qry,$j, $k) . /td;
   }

   ?/tr?php

   }
}

?
/table
br
br
a href=http://localhost/index.html;Main Page/a
br
br
a href=http://localhost/ipsearch2.html;IP Address Search/a/br/br
/br
/br
/body
/html


[/snip]


i had posted some time back that i have problems with pagination and got alot 
of help , but the problem is i have never known how to put the code together 
with what i have .. any help is appreciated...


cheers





















On Tuesday 04 January 2005 04:17, Jochem Maas wrote:
 David Ziggy Lubowa wrote:
  On Tuesday 04 January 2005 10:10, David Ziggy Lubowa wrote:
 Hey guys ,
 
  I was wondering , i have 16 records within a table in my Database , i
  have managed to have a form which can add and modify the records. My
  only problem is how i can display on a form when i search. Can someone
  give me heads up on how i can code this in php, to display the records
  in a tabular manner when i search.

 how does somebody manage to create a working script to insert/update
 data in a table and not be able to figure out how to output a simple
 HTML table listing the current records?
 I mean, do you want us to teach you how to write PHP? (My rate is
 40euros/hour)

 --
 Sorry David but your email shows little to no effort on your part to:

 a, define you problem succinctly
 b, show context (e.g. code,SQL snippets)
 c, show that you have made a decent effort to work the problem.

 given those facts you can consider yourself lucky to recieve any replies
 at all.

 ANYWAY... seeing as I'm bitchin' at ya I might as well give you a small
 clue

 the process, roughly speaking is:

 1. do a SQL select query. (e.g. SELECT id,name FROM mytable)
 2. loop thru the result, for each row output some HTML for a table row
   e.g.

   echo '
   tr
   tda href=/edit.php?id='.$row['id'].'edit/td
   td'.$row['id'].'/td
   td'.$row['name'].'/td
   /tr'
 3. don't forget to add begin- and ending TABLE tags.


 try googling 'display a MYSQL result set with PHP':
 I came up with:
 http://juicystudio.com/tutorial/php/mysql.asp
 (which is pretty funny cos the guy wrote a tutorial on mysql/php on an
 ASP based site!!)

  sorry i meant 16 fields  not records : )

 whether you tables has 16 rows or fields seems to me to be completely
 irrelevant.

 Any help is highly appreciated.
 
 
 cheers
 
 -Z

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