I'm pretty new to programming, and i'm writing a pretty simple website for an outlet, with 4 pages: home, beauty, wellbeing, contacts.
This website will be a showroom for this outlet's articles, which will be shown in the two section of the website, depending on their area of interest.
The contractor wanted of course to be able to upload articles on his own when he wanted, so I build a simple application in php, with a login, an administration page, where he could just write Title, price, description and upload an image for the article.
All is all right, The php program is ok, uploads go smooth, the page with the articles are automatically generated by the php program, which takes the data from the mysql database, via a while cycle.
The last problem which I cannot solve, is a Slider in the homepage.
The same identical in the article's pages, have to be shown in a in home page, but not one under the other, instead they must scroll in a div, and of course the article's divs are generated by the php program.
Now, i'm not all that great in javascript, so I don't know if I'm doing it the right way, or if something's wrong with the jquery plugin I use.
The code is this:
In the header:
<script src="js/jquery.jshowoff.min.js" type="text/javascript"></script>
And in the Body:
<div id="vetrina">
<?php
include "database.php";
$connection = Database::getConnection();
$query = ("SELECT * FROM `articoli` WHERE (`importante_art` = 'si') ORDER BY `id_art` DESC");
$ris = $connection->query($query) or die (mysqli_error())
$row_cnt = $ris->num_rows;
if(($row_cnt) > 0){
$row = "";
while ($row = mysqli_fetch_array($ris)){
$id_post = $row['id_art'];
$titolo_post = stripslashes($row['titolo_art']);
$testo_post = stripslashes($row['descrizione_art']);
$immagine_post = $row['immagine_art'];
$prezzo_post = $row['prezzo_art'];
echo '<div class="evidenziato">';
echo '<h4 class="titolo_evidenziato">'.$titolo_post.'</h4>';
echo '<p class="prezzo">'.$prezzo_post.'</p>';
echo '<img class="img_evidenziato" src='.$immagine_post.'></img>';
echo '<p class="descrizione_articolo">' . $testo_post . '</p>';
echo '</div>';
}
}else{
echo "Right now there are no articles to display";
}
?>
</div>
<script type="text/javascript">
$(document).ready(function(){ $('#vetrina').jshowoff(); });
</script>
I used the showoff plugin, that should do what i want.
http://ekallevig.com/jshowoff/
I don't know what I'm doing wrong... :\
I even tried to do the slideshow without the php program, by simpli typing in the articles, but nothing.
I tried 5 different plugins.
Maybe it's just that i'm doing something wrong at the base.
Anyway, my divs come out all right, i see that they are all there, but they just wont slide...
as mentioned at http://ekallevig.com/jshowoff/ site
for jshowoff required two files.
1). the jQuery Core JavaScript Library (1.3+)
2). jquery.jshowoff.min.js
Did you used both files?.
Related
I'm doing a photo gallery for my site and I wanted to have all my added photos in database. I did everything good. Database responses with the "custom link" .. I mean for example that my photo has src like something.php?id=25 .. what I want is to open this image in fancybox (I already have fancybox installed on webpage, it shows normal-src-images well), but I'm not so good in js, etc. So I don't really know what should I do...
Basicly, the problem is that everytime I want to open the image, browser shows me image in his actual src, not in fancybox.
I did this, but It doesn't work:
<script type="text/javascript">
$(document).ready(function() {
$(".selector").fancybox({
'type' : 'image'
});
});
</script>
I found this script content -- $(".selector").fancybox({'type' : 'image'}); -- on the official web page of fancybox (they said it would help when I'm trying to open images from custom links), but It just doesn't work or I inserted it bad. I don't really know what I'm doing in js or jquery or what it is... can you guys help me with it ?
Here is a part of the source code from my gallery.php where I want fancybox to work (all scripts for fancybox are set good):
<div class="images">
<?php
include_once('actions/db_connection.php');
$query = "SELECT * FROM gallery";
$response = mysql_query($query, $connection)
if(!$response)
{
mysql_error();
}
else
{
while($qs = mysql_fetch_array($response))
{
echo '<a class="fancybox" rel="group" href="actions/download_large.php?image_ID='.$qs['image_ID'].'">
<img class="gallery" alt="image" src="actions/download_small.php?image_ID='.$qs['image_ID'].'"></a>';
}
}
?>
</div>
As I told my php "script" is showing my images good, so I think I just need some script to tell the fancybox how to open a link, but If you see something bad in code I'm opened for suggestions. Thank you so much. (Sorry for my english, hope you understand).. I'm running fancybox 2.
Can you try this,
$(".fancybox").fancybox({'type' : 'image'});
instead of
$(".selector").fancybox({'type' : 'image'});
I am currently in the process of trying to build a screenshot gallery. I have complete the first step which is to make it possible for the user to upload the image to a mysql database.
That is how the images for the gallery are supplied to the gallery script. Unfortunately, I have spent months perfecting my ability to get various things into a database, but not so much time on how to take them from the database and display in a user friendly format.
Twitter Bootstrap Fluid Grid System
Twitter Bootstrap utilizes a fluid grid system to display data. You don't have to use it, but it makes for a much better looking layout. Now the screenshot gallery needs to display rows of images and each row is 4 columns wide. Now here is the kicker, This is the structure for each row.
http://pastebin.com/HvBK5rTC
I need to generate that row over and over. But I need the images that populate it to cease at 4, echo the appropriate closing divs, echo the opening divs for another row, and the echo four more images out, ect, ect.
I don't have any code for this because I do not know where to start. I can supply anything that you need if you can just help me get started.
Edit
This is what I have come up with so far, but I do not know how to close the <div class="row-fluid"> and open a new one.
http://pastebin.com/EADji2eh
You are pretty much there. mysql_* fn's are deprecated, you should use PDO etc.
You can do what you need by adding an outer loop for flow control, and using what you had already as an inner. The result array, it will automatically iterate through the result set for you without needing to keep track of offsets for limits etc.
build_gallery_fn.php:
function image_from_database() {
// use a running counter for flow control of the outer loop
$runningcount = 0;
$r = mysql_query("SELECT DISTINCT logo AS `img` FROM NewsArticles WHERE logo IS NOT NULL AND logo !='';");
//Get # of images in results to use as upper limit for outer loop
$img_ct = mysql_num_rows($r);
while ($runningcount <= $img_ct){
//rowcount reset to break content blocks
$rowcount = 0;
echo "<div class=\"row-fluid\">";
$runningcount++;
while(($rowcount <= 3) && $row = mysql_fetch_assoc($r))
{
$rowcount++;
$img = $row['img'];
echo '<div class="span2">';
echo "<span class='thumbnail'><img src='attachments/logos/$img'/> Photo # $runningcount of $img_ct</span>";
echo '</div>';
}
echo "</div>";
}
}
Output Holder:
<div class="container">
<h1 class="text-center">The American Pacific Group ScreenShot Gallery</h1>
<hr>
<?php
echo image_from_database();
?>
</div>
I have a headbreaking question on one of my projects. I want to render a specifications div from an another website into mines (I've permission).
It concerns the following website: http://www.gsmarena.com/htc_one_x-4320.php
The div: <div id="specs-list"></div>
Now I have the following code:
<?php
function get_content_part($part=null, $website = null)
{
$website = file_get_contents($website);
$data = str_replace("\n", '', $website);
echo preg_match("/\<div class\=\"'.$specs-list.'\"\>(.*)<\/div\>/",$data,$match);
return $match;
}
?>
But because the link is different with every product, I made a custom field within wordpress. The URL renders with the following code:
<?php echo(types_render_field("gsmlink", array("alt"=>"gsmlink","proportional"=>"true"))); ?>
This renders a completely clean source code, only the text.
Now I seriously have NO idea where I've to put this data so the script knows which URL and which div. Can someone help me with this?
I'll try to explain the situation as clearly as I can.
I've got a system in place that presents links to events, created with JEvents for those familiar(in Joomla)
When an event is created in the admin, the category view for it displays a little table, with the event`s date, name, and a link to the event page. All that works fine. Now the link is called on a separate php file than the one that renders the html view for it all.
The link is called with this:
<a class="ev_link_row" href="<?php echo $rowlink; ?>" <?php echo $args;?> style="font-weight:bold;color:<?php echo $fgcolor;?>;" title="<?php echo JEventsHTML::special($row->title()) ;?>"><?php echo $tmpTitle ;?></a>
On the html rendering script, I've got this:
$this->viewEventRowNew ( $row,'view_detail',JEV_COM_COMPONENT, $Itemid);
Which is comprised in a for loop above, populating the $row variable with all sorts of info.
for( $r = 0; $r < $num_events; $r++ ){
$row = $data['rows'][$r];
etc.
Now to the question. I've got a table that stores imagefile names. I have no trouble creating a forloop that goesthrough the rows and returns the path name to the images, like this:
$db = & JFactory::getDBO();
$query2 = "SELECT `c`.`filename` AS `iname` , `c`.`filetitle` AS `ititle` , `c`.`ev_id` AS `eventid` FROM `#__jev_files` AS `c` ";
$db->setQuery($query2);
$imagelist = $db->loadObjectList();
?>
<?php foreach($imagelist as $row) : ?>
<img src="/images/stories/jevents/<?php echo $row->iname; ?>" />
<?php endforeach; ?>
Now the obvious question, how do I assign this image to be comprised in the link. I tried wrapping the for loop around the linkitself, but it obviously breaks hell as it is reused in a loop(creating a loop within a loop and destroying my layout)
If I use the query in the html-rendering page, then my problem is essentially that I do not know how to append the above to the $row variable without breaking the rest of the functionality.
Thanks, a LOT to anyone who can guide me on this.
I think I could give just the answer you're looking for if I could understand the question better. Perhaps some of what you're saying is Joomla-specific so I don't quite get it.
But generally, object-oriented programming is a good way to keep information about one related thing together, such as all date, description, and collection of images associated with one event. If you can loop through a set of id's and each ID can be used to create an Event object, then each Event object can be made to retrieve it's own information and related images. It keeps code like this cleaner.
This question already has answers here:
Closed 11 years ago.
Possible Duplicates:
How to write a crawler?
Best methods to parse HTML
I've always wondered how to do something like this. I am not the owner/admin/webmaster of the site (http://poolga.com/) however the information I wish to obtain is publicly available. This page here (http://poolga.com/artists) is a directory of all of the artist that have contributed to the site. However the links on this page go to another page which contains this anchor tag which contains the link to the artist actual website.
<a id="author-url" class="helv" target="_blank" href="http://aaaghr.com/">http://aaaghr.com/</a>
I hate having to command + click the links in the directory and then click the link to the artists website. I would love a way to have a batch of 10 of the artist website links appear as tabs in the browse just for temporary viewing. However just getting these href's into some-sort of array would be a feat itself. Any idea or direction / google searches within any programming language is great! Would this even be referred to as "crawling"? Thanks for reading!
UPDATE
I used Simple HTML DOM on my local php MAMP server with this script, took a little while!
$artistPages = array();
foreach(file_get_html('http://poolga.com/artists')->find('div#artists ol li a') as $element){
array_push($artistPages,$element->href);
}
for ($counter = 0; $counter <= sizeof($artistPages)-1; $counter += 1) {
foreach(file_get_html($artistPages[$counter])->find('a#author-url') as $element){
echo $element->href . '<br>';
}
}
My favourite php library for navigating through the dom is Simple HTML DOM.
set_time_limit(0);
$poolga = file_get_html('http://poolga.com/artists');
$inRefs = $poolga->find('div#artists ol li a');
$links = array();
foreach ($inRefs as $ref) {
$site = file_get_html($ref->href);
$links[] = $site->find('a#author-url', 0)->href;
}
print_r($links);
Code, I think, is pretty self-explanatory.
Edit: Had a spelling mistake. It would take the script a really, really long time to finish, seeing as how there are so many links; that's why I used set_time_limit(). Go do other stuff and let the script run.
Use some function to loop through the artist subpages (using jQuery as an example):
$("#artists li").each();
(each entry is under a <li> inside the <div id="artists">)
Then you will have to read each page search for the element <div id="artistSites"> or the <h2> id="author">
$("#author a").href();
The implementation details will depend on how different each page is. I only looked at two, so it may be a little more complicated than this.