Current location: Hot Scripts Forums » Programming Languages » PHP » Grab data from mysql resualt and How to make this eregi work ?


Grab data from mysql resualt and How to make this eregi work ?

Reply
  #1 (permalink)  
Old 12-24-04, 04:06 PM
websnow websnow is offline
Newbie Coder
 
Join Date: Jun 2003
Location: London
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Grab data from mysql resualt and How to make this eregi work ?

I have some problem with eregi it doesn't work well when I querry alots of datat from mysql

This code is for grab from mysql result and display
it will display from $start to $end
this code will work very well if $row['title'] haven't got so many lines

But if have got many lines it will display
it will display from $start and pass over $end
It doesn't stop at $end

how to make this code work perfect ?




code

PHP Code:



$query  
"SELECT title FROM Link where (id >=1) and (id <=20 )";
$result mysql_query($query);

while(
$row mysql_fetch_assoc($result))
{
  
$row_title $row['title'] ;




$start ="<!---START HERE -->";
$end ="<!---END--->";

//========  should i put some more line before  $search = eregi inorder to make work perfect ?

$search eregi("$start(.*)$end"$row_title$printing); 
echo 
$printing[0]; 

Last edited by websnow; 12-24-04 at 04:09 PM.
Reply With Quote
  #2 (permalink)  
Old 12-24-04, 04:12 PM
websnow websnow is offline
Newbie Coder
 
Join Date: Jun 2003
Location: London
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
if i use just

PHP Code:

$query  "SELECT title FROM Link where id =1 "
and id haven't go much of content it will display perfect start $start and stop at $end


but if

PHP Code:

$query  "SELECT title FROM Link where (id >=1) and (id <=20 )"
I will start to display at $start and will not stop at $end it will passover


how can i make it work perfect ?
Reply With Quote
  #3 (permalink)  
Old 12-24-04, 04:14 PM
websnow websnow is offline
Newbie Coder
 
Join Date: Jun 2003
Location: London
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Is something wrong with this line or do i have to add some more thing before this line ?

PHP Code:

$search eregi("$start(.*)$end"$row_title$printing); 

echo 
$printing[0]; 
Reply With Quote
  #4 (permalink)  
Old 12-24-04, 07:30 PM
xtremenw xtremenw is offline
Newbie Coder
 
Join Date: Dec 2004
Location: Tacoma, WA
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
I have read through this a couple of times and do not understand what you are trying to do. In your while statement, $row_title gets reset on each row that is returned from SQL. But only the last row is used. Also, you are trying to do a 'find and replace' when you are using eregi which is a search only function... Please give more detail and maybe some example data from your database and that might help, me at least, understand what you are trying to do.
Reply With Quote
  #5 (permalink)  
Old 12-25-04, 03:24 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
use eregi_replace and echo the search var instead of printing
Reply With Quote
  #6 (permalink)  
Old 12-25-04, 01:14 PM
websnow websnow is offline
Newbie Coder
 
Join Date: Jun 2003
Location: London
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by xtremenw
I have read through this a couple of times and do not understand what you are trying to do. In your while statement, $row_title gets reset on each row that is returned from SQL. But only the last row is used. Also, you are trying to do a 'find and replace' when you are using eregi which is a search only function... Please give more detail and maybe some example data from your database and that might help, me at least, understand what you are trying to do.
`


What i try to do is grab data and list some document
display from $start to $end
or display from <!---START HERE --> to <!---END--->


#######
// example of data in mysqld from ID 1 - ID 3


ID = 1
Title =
Hello HOTSCRIPTS.COM
Programming talk
<!---START HERE -->
vb forums
xxxxxxx
yyyyyy
Last line


ID =2
Title =
first line of id=2
xxxxxxxxxxxxxxx
xxxxxxxxxxx
xxxxxxxxyyyyydsdfsdfs



ID =3
Title =
first line of ID=3
sdfsdfsdfsdf
sdfsdfsdfsdfsd
<!---END--->
sdfsdfsdfsdfs
xxxxxxxxxxxxxxxx
dfdfdfdfdfdfd english usa
33xczxczxsadfdf

*********************

from above I want to display some data from ID 1-3
display start from $start to $end
and I use eregi


code I use for this


PHP Code:

$query  "SELECT title FROM Link where (id >=1) and (id <=3 )"
$result mysql_query($query); 

while(
$row mysql_fetch_assoc($result)) 

  
$row_title $row['title'] ; 




$start ="<!---START HERE -->"
$end ="<!---END--->"


$search eregi("$start(.*)$end"$row_title$printing); 
echo 
$printing[0]; 

result I will have is it will display from $ start to $end

vb forums
xxxxxxx
yyyyyy
Last line


ID =2
Title =
first line of id=2
xxxxxxxxxxxxxxx
xxxxxxxxxxx
xxxxxxxxyyyyydsdfsdfs



ID =3
Title =
first line of ID=3
sdfsdfsdfsdf
sdfsdfsdfsdfsd

-------------

but if ID 1-ID3 has many content on it

the result will start $start but will not stop at $end

or some time didn't display anything or sometime display all content

Last edited by websnow; 12-25-04 at 01:18 PM.
Reply With Quote
  #7 (permalink)  
Old 12-26-04, 02:26 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
this is what you do
PHP Code:

$query  "SELECT title FROM Link where (id >=1) and (id <=3 )"#select id 1-3

$result mysql_query($query); 

while(
$row mysql_fetch_assoc($result)) #fetch em

  
$row_title $row['title'] ; #for every time the loop goes you override $row_title and the old value dissapears




$start ="<!---START HERE -->"
$end ="<!---END--->"


$search eregi("$start(.*)$end"$row_title$printing); #$row_title contains the last id.
#also when counting arguments this really looks like a replace
echo $printing[0]; #doesint have a value 
this is a untested version of a way you could do it:
PHP Code:

$query  "SELECT title FROM Link where (id >=1) and (id <=3 )"#select id 1-3

$result mysql_query($query); 

while(
$row mysql_fetch_assoc($result)) #fetch em

  
$titles .= $row['title'] ; # .= adds to the end of variable


$start ="<!---START HERE -->"
$end ="<!---END--->"

$search preg_replace("/$start(.*)$end/i""\\0"$titles);
echo 
$search
Reply With Quote
  #8 (permalink)  
Old 12-26-04, 12:37 PM
websnow websnow is offline
Newbie Coder
 
Join Date: Jun 2003
Location: London
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you very much for your help
and i will try your code
Reply With Quote
  #9 (permalink)  
Old 12-27-04, 09:47 AM
websnow websnow is offline
Newbie Coder
 
Join Date: Jun 2003
Location: London
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
hello <?Wille?>

the code you wrote i test it

it's work and display everything from ID1-ID3
but it didn't grab data to just display from $start to $ end

is it possible to grab and disaplu data only in $start - $ end ?
Reply With Quote
  #10 (permalink)  
Old 12-27-04, 10:59 AM
websnow websnow is offline
Newbie Coder
 
Join Date: Jun 2003
Location: London
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
here this is working code

it will grab data fromo $start to $end

But if have got many lines it will display
it will display from $start and pass over $end
It doesn't stop at $end

how to make this code work perfect ?




PHP Code:

$connection mysql_connect ($host$user$password) or die ("Coudn't connect .");

if (
$connection) {
$msg="Success !";
}

$db=@mysql_select_db($db_name$connection) or  die ("Coudn't connect 11.");

// Querry data
$sql="
SELECT `sid` , `title`
FROM 
$table_name   WHERE  ( `sid`  >=  100001   ) and ( `sid`  <=  100010)
"
;
$result= @mysql_query($sql,$connection) or  die ("Coudn't  execuse query.");

// loop
while($row mysql_fetch_array($result))


// echo $row['title'] ;
$title .= $row['title'] ; 
}

// grab 
eregi("$start(.*)$end"$title$head);


echo 
$head[0]; 

Last edited by websnow; 12-27-04 at 11:35 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 05:23 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.