Jump to content

yujikaido

Members
  • Posts

    27
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

yujikaido's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for the reply and the help. I tried the line but i get: Warning: preg_match_all() expects parameter 2 to be string, array given in /Applications/XAMPP/xamppfiles/htdocs/falculty.php on line 5" when I run it. any suggestions ? <? $url = "http://www.cs.iusb.edu/people/faculty.html"; //set the web address to an array $input = file_get_contents($url) or die('Could not access file: $url'); // input get set to grab the contents of the page or else displays msg. if (preg_match("/<table id=\"table1\" .*?\<tbody\>(.*?)\<\/tbody\>/s",$input,$outp));// preg match first sets the expression to grap table1 and then processing it with $input array and sets the result to $outp array preg_match_all("/(<ul.*>)(\w.*)(<\/ul>)/isxmU",$outp,$matches); echo $matches[0];// ouputs the completed table echo $matches[1];// ouputs the completed table echo $matches[2];// ouputs the completed table ?>
  2. I now got it to pull the table correctly now I somehow have to change the table color and instead of the table being horizonal it has to be vertically stacked with faculty on top Ass. faculty in the middle and staff on the bottom. Does anybody have any idea how I might go about this? Thanks
  3. Ok I got it to output the html table I wanted but it lost its table format. this is what I want my end result to look like at this address http://www.cs.iusb.edu/~rbatzing/a340/faculty.php so I want to grab the first table "table1" in the body. Thanks <? $url = "http://www.cs.iusb.edu/people/faculty.html"; $input = file_get_contents($url) or die('Could not access file: $url'); if (preg_match("/id=\"table1\" .+?\<tbody\>(.+?)\<\/tbody\>/s",$input,$outp)); echo $outp[1]; ?>
  4. Hey thanks for the reply. OK I took out the @. and I tested that line of code but got the same result.
  5. Could anyone please tell what I am doing wrong with my code? I just get a blank page when I echo output and run it on xamplite. Thanks <? $url = "http://www.cs.iusb.edu/people/faculty.html"; $input = @file_get_contents($url) or die('Could not access file: $url'); $pat = "/id=\table1\" .+\<tbody\>(.+)\<\/tbody\>/s"; preg_match($pat,$input,$outp); echo $outp[1]; ?>
  6. I am still working on this and not getting anywhere to quick. So far I can input a url and I had it to ouput the website before I started messing with the code. What I want preg_match to do is step 1 is output only table 1 in the body of the website http://www.cs.iusb.edu/people/faculty.html. then step 2 I want to stack it in a narrow table like this final project. http://www.cs.iusb.edu/~rbatzing/a340/faculty.php I dont want to use any expression or method but preg_match and I think I need to use preg_match_all for step 2 but I am not sure. I dont want to use DOM. here is my code so far. Please help a guy out. I need some guidance please. :'( Thanks. <? $url = "http://www.cs.iusb.edu/people/faculty.html"; $input = @file_get_contents($url) or die('Could not access file: $url'); if preg_match("/id=\table1\" .+\<tbody\>(.+)\<\/tbody\>/s,$outp); echo $outp ; ?>
  7. It needs to look like this example. http://www.cs.iusb.edu/~rbatzing/a340/faculty.php
  8. I am working on a php file to extract tables from a website and rearrange them in a vertically stacked order of a single table. Its for an assignment so don't just give me the answer help me find the answer. I know a I need to develop a expression like preq_match() and use a maybe similar to /id=\"table1\" .+\<tbody\>(.+)\<\/tbody\>/s but not sure where to go from here. D Here is my code so far. I would appreciate any help or any suggestions. Also if you know any good examples I can learn from that would be good too. Thank you. <?php $homepage = file_get_contents('http://www.cs.iusb.edu/people/faculty.html'); ## gets contents of website into array preg_match('id=\"table1\".+\<tbody\>(.+)\<\/tbody\>/s',$homepage,$array); ## supposed to extract all tables in page and post to $array print_r($array); ## print out array ?>
  9. yeah its for an assignment. :-\ I am trying to pass the class but I am not doing to tell well. I just have hard time understanding it. I have been watching the videos on lynda.com though.
  10. Oh also It maybe easier with databases but I am not allowed to use a database.
  11. Hey thanks again I really appreciate the help and the code. I have been adding a few things to it and I keep getting parse error. Yeah I am running xampplite for osx. Any other suggestions? I have also attached my css script. <html> <head> <link rel="stylesheet" type="text/css" title="styles" href="style.css" /> </head> <body> <div id="container"> <h1>East Asian Neighborhood</h1> <?php $dir = 'images'; $result = opendir($dir); $numrows = 0; while(($f = readdir($result)) !== false) if(ereg('.jpg$', $f)) ++$numrows; $rowsperpage = 10; //How many get displayed per page $totalpages = ceil($numrows / $rowsperpage); //Estimating the total of pages //Getting the current page... if (isset($_GET['page']) && is_numeric($_GET['page'])) { $currentpage = (int) $_GET['page']; } else { //Could not retreive current page, so set it as 1 $currentpage = 1; } //Checking if the current page is bigger than the total pages if ($currentpage > $totalpages) { //The current page is bigger, so display the results displayed on the last page. $currentpage = $totalpages; } //Checking if the current page is smaller than 1 if ($currentpage < 1) { //The current page is smaller, so display the results dislpayed on the first page. $currentpage = 1; } $offset = ($currentpage - 1) * $rowsperpage; //Not sure about this, so dont change it //Just change the query bit, do not change past "DESC LIMIT $offset, $rowsperpage" It IS needed. $result = opendir($dir)("SELECT * FROM tblname DESC LIMIT $offset, $rowsperpage") ; //Displaying the results in an loop. while ($list = opendir($dir)($result)) { echo "Images get displayed here."; echo "EG:"; echo "<img src=\"".$list['image']."\" border=\"0\" />"; } echo 'Pages: '; //Echo the word Pages $range = 3; //Page range on display. range 3, will display '1,2,3' or '2,3,4' for example //if current page is bigger than 1... if ($currentpage > 1) { //display << to navigate to first page echo " <a href='{$_SERVER['PHP_SELF']}?page=1'><<</a> "; //Display < to go back 1 page $prevpage = $currentpage - 1; echo " <a href='{$_SERVER['PHP_SELF']}?page=$prevpage'><</a> "; } else { //display << to navigate to first page echo " <a href='{$_SERVER['PHP_SELF']}?page=1'><<</a> "; //Display < to go back to the first page as you dont need to go back to prev page as you aren't past page 1. $prevpage = $currentpage - 1; echo " <a href='{$_SERVER['PHP_SELF']}?page=1'><</a> "; } //This little function echo's the page numbers etc at the bottom. for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { if (($x > 0) && ($x <= $totalpages)) { if ($x == $currentpage) { echo " [<b>$x</b>] "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?page=$x'>$x</a> "; } } } //If the current page isn't the maximum number of pages if ($currentpage != $totalpages) { $nextpage = $currentpage + 1; //Display > to go to next page. echo " <a href='{$_SERVER['PHP_SELF']}?page=$nextpage'>></a> "; //Display >> to go to last page. echo " <a href='{$_SERVER['PHP_SELF']}?page=$totalpages'>>></a> <br /><br /><br />"; } else { //Display > to go to last page. echo " <a href='{$_SERVER['PHP_SELF']}?page=$totalpages'>></a> "; //Display >> to go to last page. echo " <a href='{$_SERVER['PHP_SELF']}?page=$totalpages'>>></a> <br /><br /><br />"; } ?> </div> </body> </html> Here is my style.css file [css] a, a:visited, a:hover {} #container {position:relative; width:600px; height:700px; background:#888; border:1px solid #000; margin:10px auto; font-family:verdana, arial, sans-serif; font-size:12px;} #container a.pics {float:left; padding:7px 21px; display:inline; color:#000; text-decoration:none; width:75px; height:75px; cursor:default;} #container a.pics img.thumb {display:block; border:1px solid #000;} #container a.pics span {display:none; border:0; width:580px; background:#bbb; border:1px solid #fff; text-align:center;} #container a.pics span img {margin:10px auto; border:1px solid #000;} #container a.pics:hover {white-space:normal;} #container a.pics:hover img.thumb {border:1px solid #fff;} #container a.pics:hover span {display:block; position:absolute; left:9px; top:192px; z-index:10; height:500px;} #container a.pics:active img.thumb {border:1px solid #fc0;} #container a.pics:active span {display:block; position:absolute; left:9px; top:192px; z-index:5; height:500px;} #container a.pics:focus {outline:0;} #container a.pics:focus img.thumb {border:1px solid #fc0} #container a.pics:focus span {display:block; position:absolute; left:9px; top:192px; z-index:5; outline:0; height:500px;} #container span.info {clear:left; display:block; text-align:center; line-height:20px; margin:0; padding:200px 0 0 0; width:600px; text-align:center; color:#eee; z-index:1;} #container span.info a {color:#000;} #container span.info a:hover {text-decoration:none;} [/css]
  12. Hey many thanks looks great, so all I need to do is tell it to read an image directory instead of a database and add my style.css script to it ? I haven't started learning about sql databases yet. Are these changes below correct? <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <link rel="stylesheet" type="text/css" title="styles" href="style.css" /> </head> <?php //Grabbing the results from the database $result = /images("SELECT * FROM tblname"); ## Is this correct if I want it to read from images directory? $numrows = mysql_num_rows($result); ## Not to sure what to put here? $rowsperpage = 10; //How many get displayed per page $totalpages = ceil($numrows / $rowsperpage); //Estimating the total of pages //Getting the current page... if (isset($_GET['page']) && is_numeric($_GET['page'])) { $currentpage = (int) $_GET['page']; } else { //Could not retreive current page, so set it as 1 $currentpage = 1; } //Checking if the current page is bigger than the total pages if ($currentpage > $totalpages) { //The current page is bigger, so display the results displayed on the last page. $currentpage = $totalpages; } //Checking if the current page is smaller than 1 if ($currentpage < 1) { //The current page is smaller, so display the results dislpayed on the first page. $currentpage = 1; } $offset = ($currentpage - 1) * $rowsperpage; //Not sure about this, so dont change it //Just change the query bit, do not change past "DESC LIMIT $offset, $rowsperpage" It IS needed. $result = /Images("SELECT * FROM tblname DESC LIMIT $offset, $rowsperpage") or trigger_error('Query failed: '. mysql_error()); //Displaying the results in an loop. while ($list = /Images($result)) { ## this corrrect? echo "Images get displayed here."; echo "EG:"; echo "<img src=\"".$list['image']."\" border=\"0\" />"; } echo 'Pages: '; //Echo the word Pages $range = 3; //Page range on display. range 3, will display '1,2,3' or '2,3,4' for example //if current page is bigger than 1... if ($currentpage > 1) { //display << to navigate to first page echo " <a href='{$_SERVER['PHP_SELF']}?page=1'><<</a> "; //Display < to go back 1 page $prevpage = $currentpage - 1; echo " <a href='{$_SERVER['PHP_SELF']}?page=$prevpage'><</a> "; } else { //display << to navigate to first page echo " <a href='{$_SERVER['PHP_SELF']}?page=1'><<</a> "; //Display < to go back to the first page as you dont need to go back to prev page as you aren't past page 1. $prevpage = $currentpage - 1; echo " <a href='{$_SERVER['PHP_SELF']}?page=1'><</a> "; } //This little function echo's the page numbers etc at the bottom. for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { if (($x > 0) && ($x <= $totalpages)) { if ($x == $currentpage) { echo " [<b>$x</b>] "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?page=$x'>$x</a> "; } } } //If the current page isn't the maximum number of pages if ($currentpage != $totalpages) { $nextpage = $currentpage + 1; //Display > to go to next page. echo " <a href='{$_SERVER['PHP_SELF']}?page=$nextpage'>></a> "; //Display >> to go to last page. echo " <a href='{$_SERVER['PHP_SELF']}?page=$totalpages'>>></a> <br /><br /><br />"; } else { //Display > to go to last page. echo " <a href='{$_SERVER['PHP_SELF']}?page=$totalpages'>></a> "; //Display >> to go to last page. echo " <a href='{$_SERVER['PHP_SELF']}?page=$totalpages'>>></a> <br /><br /><br />"; } ?> </html>
  13. pagination seems a little complicated how about this I use a shuffle() function to randomize the pictures in the array Output a <div> with the id set to "container". and use a loop to output the first 10 pictures in the randomized array via the following code. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <link rel="stylesheet" type="text/css" title="styles" href="style.css" /> <?php list($picname,$picdesc) = explode('|',$pics[$index]); echo <<<endmsg <a class="pics" href="#nogo"><img class="thumb" src="$dir$picname-t.jpg" alt="" /> <span><img src="$dir$picname.jpg" alt="$picdesc" title="$picdesc" /><br />$picdesc</span> </a> endmsg ?> [ Any suggestions
  14. Also I have all of my images already done cropped manually in thumbnails in 45x45 pixels and my large images already 450x450 so I don't need any functions to do that for me.
  15. Thanks for all the replies but I need to do this without a database. I need it to pull images from a images directory. I have seen some stuff on pagination, I will have to look up on it more. i am thinking i need to make a php file that loads the style sheet with my css styles in styles.css then load the contents of file containing the list of pictures and captions into an array. So I just need one php file and css stylesheet I think. Any help on how I can start my code or any scripts anyone know of that has the same functions. Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.