Solved

Append number to array

Posted on 2014-12-02
19
130 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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
 
LVL 12

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 110

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 12

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 110

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

718 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