Canman2005
-
Posts
669 -
Joined
-
Last visited
Never
Posts posted by Canman2005
-
-
hummmm
cant seem to get either of them to produce the correct result
no errors, just either nothing showing or in a format that I cannot seem to decode
any ideas?
-
Hi all
I am doing some work with dates and I need some help.
I basically have the code
<?php $date = 'month=$_GET['month'].'&year='.$_GET['year']; print $date; ?>
with a url of
page.php?month=02&year=2003
it produces something like "month=02&year=2008"
What I want to do is also be able to print last months date and also next months date, so with the above URL it would print
month=01&year=2008
month=02&year=2008
month=03&year=2008
Does that make sense?
Can anyone help?
Thanks in advance
Dave
-
Cracked it
Thanks for the help, your query pretty much did what I wanted
Peace out
-
Hi
I think its
SELECT * FROM wp_postmeta INNER JOIN wp_posts ON post_id = wp_posts.ID WHERE wp_posts.ID = '75' AND `meta_key` = 'promo' AND `meta_value` = 'category title'
-
basically I have a table which holds main categories and for each row in that table, there is an ID number, that ID number relates to another table which holds the articles relating to the category which its ID it stores.
If that makes sense
what i want to do is group all the categories together so that rather than repeating duplicate categories, it just shows one of each. i then want to pull all the articles relating to the category listed under it.
so results would look like
category 1
> article 1
> article 2
> article 3
category 2
> article 4
> article 5
category 3
> article 6
> article 7
the problem is that because I run a GROUP BY it only returns one ID number of each category grouped, so even if there were 10 categories listed, it would only return the first ID number, this means you only get one reference to the article ID number and the other ones are lost.
does that make any sense
-
Thanks
I can see where you going, but for some reason that is returning every row in the "wp_posts" table
Any ideas?
-
the main problem is that in the table where the data that we need is, there is no reference back to the table which holds which category they are in.
its most likley something simple, but so hard to explain
-
Hi
So what do I change
$querystr = "SELECT * FROM `wp_posts` WHERE `ID` = '".$row1['post_id']."'";
to??
i'm picking one row with the above query, therefore the code you showed would only run on that one row.
Do I need to alter that query?
Thanks
-
Hi
Doesnt make sense, sorry, think its too long on this problem has fried my brain
Could you explain further?
Thanks
Dave
-
Hi all
I'm wondering if anyone can help, I have been trying to crack this for hours and cannot seem to find a way to solve it
Basically i'm using WordPress but tweaking some of the code to fit the site I have built.
Please bear with me, I am going to try and give as much information as I can.
Let me start by giving you a quick overview of the databases.
There are two main databases, one called "wp_postmeta" which contains the posts and then another table called "wp_posts" which holds the full details of the post.
A small dump of the two databases are
--------------------------------------------------------------
wp_postmeta
meta_id | post_id | meta_key | meta_value
4 33 promo day event
5 34 promo weekend event
6 35 promo christmas event
7 36 promo day event
--------------------------------------------------------------
wp_posts
ID | post_author | post_date_gmt | post_title
33 dave smith 2007-01-08 08:17:52 test post
34 john wilks 2007-01-09 12:23:11 another post
35 dave smith 2007-01-11 13:21:43 another one
36 chaz dome 2007-01-11 14:54:02 my last post
--------------------------------------------------------------
the following is my QUERY, I will explain how it works and the problem I have at the bottom, if you want to see more of the QUERY, please let me know.
$sql = "SELECT * FROM `wp_postmeta` WHERE `meta_key` = 'promo' GROUP BY `meta_value` ORDER BY `meta_value` ASC"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { print $row['meta_value']; $sql1 = "SELECT * FROM `wp_postmeta` WHERE `meta_value` = '".$row['meta_value']."'"; $result1 = mysql_query($sql1); $rows2 = mysql_num_rows($result1); $i = 1; while ($row1 = mysql_fetch_assoc($result1)) { $querystr = "SELECT * FROM `wp_posts` WHERE `ID` = '".$row1['post_id']."'"; $pageposts = $wpdb->get_results($querystr, OBJECT); if ($pageposts): foreach ($pageposts as $post): setup_postdata($post);
Okay, so what it does initally is look in the "wp_postmeta" table and returns all rows that have a "meta_key" value set as "promo", so the results look like
day event
weekend event
christmas event
day event
it then does a
GROUP BY meta_value
which returns the results as
day event
weekend event
christmas event
(as day event is listed twice under "meta_value", the GROUP BY only shows one)
The next QUERY looks in "wp_postmeta" and uses the "meta_value" from the last QUERY to grab the details of that row.
Finally it does one last QUERY for each row returned, uses the "post_id" to look in "wp_posts" and grab the row with the "id" number which matches the "post_id" returned in the previous QUERY.
So you end up with the results
day event
> test post (2007-01-08 08:17:52)
> my last post (2007-01-11 14:54:02)
weekend event
> another post (2007-01-09 12:23:11)
christmas event
> another one (2007-01-11 13:21:43)
Does that make sense? Maybe a little too detailed, but hopefully it will help you to make sense.
Right, my problem.
Because there might be multiple posts with the same "meta_value" (from "wp_postmeta") and the same "post_title" (from "wp_posts"), the resuls could look like
day event
> my post (2007-01-08 08:17:52)
> my post (2007-01-11 14:54:02)
As you can see, there is a "my post" twice, this is what I want to overcome.
The way I want to overcome this, it by ordering them by date, so the above results would look like
day event
> my post (2007-01-11 14:54:02)
> my post (2007-01-08 08:17:52)
Showing the row with the latest date first.
The problem is that the date information is stored in the table "wp_posts", but the QUERY which sorts the ORDER of the rows retured comes from the table "wp_postmeta", which doesnt contain any date information.
Does this make any sense? Can anyone please help me?
Any help would be ace
Thanks in advance
Dave
-
hi all
i have been battling against a alteration to a query for a couple of days now and im totally stuck, i will try and explain what i have.
basically i have a query, it produces a bunch or results on a php page which look like
news
article 1
event
article 2
profile
article 3
news
article 4
profile
article 5
the bit where is says "profile", "news" or "event", this is the heading and then under the heading it lists the article related to that heading.
to get this, i used the following query
<?php $querystr = "SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'promo' AND wposts.post_status = 'publish' AND wposts.post_type = 'post' ORDER BY wpostmeta.meta_value ASC"; $pageposts = $wpdb->get_results($querystr, OBJECT); ?> <?php if ($pageposts): ?> <?php foreach ($pageposts as $post): ?> <?php setup_postdata($post); ?> <div class="titlepanel"><?php echo get_post_meta($post->ID, 'promo', true);?></div> <div class="contentpanel"> <div class="compdetails" id="competition_<?php the_ID(); ?>_details"> <p class="postdate"><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></p> <?php the_content('<p class="serif">read</p>'); ?> </div> </div>
each heading (ie: news, events) is created with the
<div class="titlepanel"><?php echo get_post_meta($post->ID, 'promo', true);?></div>
part of the code above.
What i want to do is bundle the 2 news articles together and the 2 profiles together, so the above results would look like
news
article 1
article 4
event
article 2
profile
article 3
article 5
if you add to the end of the query
GROUP BY wpostmeta.meta_value
then the results look like
news
article 1
event
article 2
profile
article 3
which is right, but I need to put a new query which returns all the news articles & profile articles under the main heading, so the above results for the "news" would NOT look like
news
article 1
but it WOULD look like
news
article 1
article 4
does that make sense?
any help would be ace as im slowing killing myself here
thanks in advance
dave
-
can anyone help?
-
hi all
we have a featured content slider script.
My html page has 14 sections to a BIG form and we have used to content slider so that once you have complete section 1 of the form, you can click the next link (or one of the page numbers) and it will take you to the next part of the form, you keep doing this until you reach section 14 (page 14) and then there is a submit on page 14 which then dumps all the form data into a sql database.
The problem I have is that I have the page numbers and a next button which allows you to move through the form, it looks like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 next
once your on section 14, if you click the `next` link, it takes you back to page 1.
the problem im running into, is that when people reach section 14, they are clicking the next button thinking that it will submit the form, where as it's not, when they click next on section 14, it takes them back to section 1.
what i want to do is to remove the link `next` when they reach section 14, or make the next link different on section 14 than it is on the other sections, so that clicking next while on page 10 for example, would take you to step 11, but clicking next on step 14 would contain a link which could submit the form.
the code I use in my page to generate the page numbers and next link is
<script type="text/javascript"> ContentSlider.buildpagination=function(sliderid){ var slider=document.getElementById(sliderid) var paginatediv=document.getElementById("paginate-"+sliderid) //reference corresponding pagination DIV for slider var pcontent="" pcontent+='<span class=people-content><strong>Page</strong></span> ' for (var i=0; i<slidernodes[sliderid].length; i++) //For each DIV within slider, generate a pagination link pcontent+='<a href="#" onClick=\"ContentSlider.turnpage(\''+sliderid+'\', '+i+'); return false\">'+(slider.paginateText? slider.paginateText[i] : i+1)+'</a>' pcontent+='<span class=people-content><a href="#" style="font-weight: bold;" onClick=\"ContentSlider.turnpage(\''+sliderid+'\', parseInt(this.getAttribute(\'rel\'))); return false\">'+(slider.nextText || "Next")+'</a></span>' paginatediv.innerHTML=pcontent paginatediv.onclick=function(){ //cancel auto run sequence (if defined) when user clicks on pagination DIV if (typeof window[sliderid+"timer"]!="undefined") clearTimeout(window[sliderid+"timer"]) } } ContentSlider("slider2") </script>
I have been hacking at this for ages, with no luck, i tried to use a if statement, but im really new to jscript modication, so its becoming a hard one to crack.
if anyone can help that would be ace
thanks in advance
ed
-
Hi all
I have a simple query, it looks like
$sql = "SELECT * FROM `thisdata` WHERE `id` = 1"; $query = @mysql_query($sql,$connection) or die(mysql_error()); while ($row = mysql_fetch_array($query)) { $datavalue1 = $row['dataone']; $datavalue2 = $row['datatwo']; $datavalue3 = $row['datathree']; $datavalue4 = $row['datafour']; $datavalue5 = $row['datafive']; }
now each $datavalue (1-5) holds a number, so the above may give
$datavalue1 = 12
$datavalue2 = 342
$datavalue3 = 4532
$datavalue4 = 2
$datavalue5 = 767
there isnt always 5 values, sometimes there maybe just 2, 3 or 4 values, such as
$datavalue1 = 54
$datavalue2 = 2
$datavalue3 =
$datavalue4 =
$datavalue5 =
is it possible to gather all the values given and then provide a percentage out of 100 for each one, so if I had 3 values then there % would be as follows
$datavalue1 = 36 - would equal 18%
$datavalue2 = 64 - would equal 32%
$datavalue3 = 100 - would equal 50%
$datavalue4 =
$datavalue5 =
Does this make sense?
Can anyone help
thanks
ed
-
thank you, works great
-
so do i put the all the queries within
$_SESSION['x']= array(
IN HERE
);
sorry, being a little thick tonight
-
only because its the standard code i use for getting data from a table
-
do you mean as
$_SESSION['sessioname']
?
-
hi all
i have a query which looks like
<?php $sql = "SELECT * FROM bes_optionals ORDER BY title ASC"; $show = @mysql_query($sql,$connection) or die(mysql_error()); while ($row = mysql_fetch_array($show)) { if($row['type'] == 1) { if($_GET[$row['id']] == 1) { print ''.$row['title'].' at a cost of £'.number_format($row['cost'], 2, '.', '').''; print "<br><br>"; } } elseif($row['type'] == 2) { if($_GET[$row['id']] == 1) { print '1 '.$row['title'].' at a cost of £'.number_format($row['cost'], 2, '.', '').''; print "<br><br>"; } elseif($_GET[$row['id']] == 2) { print '2 '.$row['title'].' at a cost of £'.number_format(($row['cost']*2), 2, '.', '').''; print "<br><br>"; } elseif($_GET[$row['id']] == 3) { print '3 '.$row['title'].' at a cost of £'.number_format(($row['cost']*3), 2, '.', '').''; print "<br><br>"; } elseif($_GET[$row['id']] == 4) { print '4 '.$row['title'].' at a cost of £'.number_format(($row['cost']*4), 2, '.', '').''; print "<br><br>"; } } } ?>
this outputs something like
RG564 at a cost of £40
C45HY at a cost of £10
is it possible to make everything that is outputted by these two queries as a session and store what has been outputed
any help would be great
thanks
ed
-
nice one
thanks very much
-
hi all
i have the following query
<?php $sql1 = "SELECT * FROM bes_optionals ORDER BY title ASC"; $show1 = @mysql_query($sql1,$connection) or die(mysql_error()); while ($row1 = mysql_fetch_array($show1)) { if($row1['type'] == 1) { if($_GET[$row1['id']] == 1) { print $row1['cost']; } } elseif($row1['type'] == 2) { if($_GET[$row1['id']] == 1) { print $row1['cost']; } elseif($_GET[$row1['id']] == 2) { print $row1['cost']*2; } elseif($_GET[$row1['id']] == 3) { print $row1['cost']*3; } elseif($_GET[$row1['id']] == 4) { print $row1['cost']*4; } } } ?>
it basically outputs a series of numbers that were selected from a form on the previous page.
the output looks something like
7.0010
which is
7.00
and
10
is it possible to add up all numbers outputted so it gives a result of 17?
any help would be ace
thanks in advance
ed
-
i mean how can i grab all the id numbers of the tick boxes selected when the form is submitted, so i can store the id numbers of the ticked boxes in a field within the database
-
can anyone help tweak a script?
we will pay for the work
-
hi all
i have a php form which contains a query, the query is used to generate a series of tick boxes
$sql = "SELECT * FROM extras ORDER BY id ASC"; $show = @mysql_query($sql,$connection) or die(mysql_error()); while ($row = mysql_fetch_array($show)) { ?> <input name="extra" type="checkbox" value="<?php print $row['title']; ?>" /> <?php }
this creates a series of tick boxes.
is it possible to somehow group the id numbers of the ones that are ticked, so it would create a variable containing all the id numbers, for example
$extrasticked = '12 ,34 ,56 ,76';
could this be done?
thanks
ed
[SOLVED] PHP Date - Last Month - Next Month
in PHP Coding Help
Posted
Thanks so much everyone
Cheers