Solved

Append number to array

Posted on 2014-12-02
19
119 Views
Last Modified: 2014-12-04
I would like to add a number to this array:

<div class="stars" data-id="<?php echo $attorneysStuff['bizID'];?>2" data-stars="10" data-title="Pricing">

<?php schema($attorneysStuff['bizID'],10);?>

</div>


So it should be like this. In this case "2" is added, but it will not work this way:

[code]

<?php schema($attorneysStuff['bizID2'],10);?>

Open in new window

0
Comment
Question by:seopti
  • 7
  • 7
  • 2
  • +1
19 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40477135
Whats the error - there is nothing wrong with the code
0
 

Author Comment

by:seopti
ID: 40477169
The problem with the code is, there is no bizID2, there is only a bizID.

So this will code will not append the number "2" to the bizID.

<?php echo $attorneysStuff['bizID2'];?> 

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 40477193
Not following you - if it doesn't exist then why are you trying to access it or do you mean

<?php echo $attorneysStuff['bizID']."2";?>
0
 

Author Comment

by:seopti
ID: 40477302
Thank you but still looking for the solution of this:

<?php schema($attorneysStuff['bizID'],2,10);?>

bizID needs the element 2 added at the and, after this ,10
0
 
LVL 58

Expert Comment

by:Gary
ID: 40477313
What is schema
0
 

Author Comment

by:seopti
ID: 40477332
schema is a function.

<?php schema('someItemID');      //print schema.org rich snippets
schema('someItemID',10);      //print schema.org rich snippets with 10 - as maximum possible rating

Usually I append a sub-id to the bizID like this:
<?php echo $attorneysStuff['bizID'];?>2

But in the case above I have to get the syntax for:
<?php schema($attorneysStuff['bizID'],2,10);?>

I'm trying this for hours but without any result.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40477341
And whats the code?
You can't ask use to help you do something and not show the code
0
 

Author Comment

by:seopti
ID: 40477366
This is the code for the schema function:

 USAGE EXAMPLE (your_file.php):
   
   <?php
   
      include_once ('www.your_site.com/path_to/snippets.php');		//include snippets.php file
      
      $itemID='myItem';		//item ID for which rich snippets will be displayed
      
      //call one of the functions, depending on which rich snippets you already use in your project
      schema($itemID);		//(recommended)
      //microdata($itemID);
      //microformat($itemID);
      //PDFa($itemID);
      
   ?>
   
   
*/





//template for schema.org
function schema($item_id, $best=5, $round=null){
    $stats = getStats($item_id, $best, $round);			//get rating from DB
    
	//in case of any database related errors
	if($stats==0) {echo ' !Error! '; return;}
	
	//dont print snippet if item has less then 1 vote to avoid google error message
//	if($stats['votes']<1) {echo '<br />item has less then 1 vote'; return;}
	
	//markup template for scheme.org. Edit it as you like.  
	$template = <<< EOF
	
	
<div itemscope itemtype="http://schema.org/CreativeWork">
	<a itemprop="url" href="{$stats['url']}">
		<span itemprop="name">{$stats['title']}</span>
	</a> 
	<span itemprop="aggregateRating"	itemscope itemtype="http://schema.org/AggregateRating">
		<meta itemprop="worstRating" content = "0">
		<span itemprop="ratingValue">{$stats['average']}</span> 
		out of <span itemprop="bestRating">{$stats['best']}</span> 
		(based on <span itemprop="ratingCount">{$stats['votes']}</span> ratings)
	</span>

</div>

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 40477392
bizID needs the element 2 added at the and, after this ,10
Doesn't make sense
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 11

Expert Comment

by:tel2
ID: 40477441
> Doesn't make sense
I'm struggling with this use of the English language too, Gary.
A bit (or even a byte) more time spent in giving enough info and writing things clearly could save everyone a lot of time in the long run, IMHO.  It's fortunate the some experts are very patient, which is impressive considering what they get "paid".
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40477534
Let's try this.

1. Please show us the data you have for input - not the code, just the data.  If you want you can use var_dump() to print out the values of the data.

2. Please show us the output you want to get from the data.

With that information we can usually show you the exact code to achieve the result.
0
 
LVL 11

Expert Comment

by:tel2
ID: 40477833
You must be better than you even know, Ray.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40477840
0
 

Author Comment

by:seopti
ID: 40482164
Of course Rays question was the answer. His question helped me solving this problem.

The other posters complained they are underpaid and it maked no sense, Ray provided a question which led to a solution so where is the problem?
0
 

Author Comment

by:seopti
ID: 40482165
Maybe you should pay the experts more so they will not be that frustrated about solving questions, just a suggestion.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40482174
posters complained they are underpaid
No one complained about being underpaid, tel2's comment was sarcasm because we are not paid.
All experts on here do it of their own free will

Now care to explain how a question asking for the data is an answer.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40482180
Maybe you should pay the experts more...
Ha!  Yes please raise my salary from E-E by at least 10%.  So many questions are answered by just getting from the initial question to the SSCCE!
0
 

Author Comment

by:seopti
ID: 40482243
They don't pay you but I pay them. So you for sure have high morals if you help poor coding souls if you are not paid :)

No rellay, they really don't pay the experts, what a shame!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now