modify loop to display message 1 time for all instances
Tag : php , By : user185283
Date : March 29 2020, 07:55 AM
To fix the issue you can do My code check the 1st 3 messages of the twitter wall and looks for a string called "code". if its there it will echo "code available" and if its not it will echo "no code". Right now it echos 3 times for each message. , How about this: function echo_messages($url,$max = 1) {
$data = json_decode(file_get_contents($url));
$counter = 0;
foreach($data->data as $post)
{
preg_match("/code/", $post->message, $code);
if (strlen($code[0])!= 0){
echo '<div id="facebook">Facebook: Code Available</div>';
return;
}
$counter++;
if($counter >= $max) break;
}
echo '<div id="facebook">Facebook: No Code</div>';
}
echo_messages('https://graph.facebook.com/234265435775/posts',3);
function hasCode($url,$max=1) {/*...*/}
echo "<div id=\"facebook\">Facebook: ".
(hasCode('https://graph.facebook.com/234265435775/posts',3)?
"Code Available":"No Code").
"</div>";
|
Using label control inside foreach loop to display multiple value in a single label
Date : March 29 2020, 07:55 AM
this will help I am really not sure what you are wanting, but if it is to add all of your Mutants dangerQuotient to your label you will need to change your foreach statement to something like this. You are currently replacing the label's contents every iteration of your foreach loop. label12.Text = ""; // or just delete the text in the designer
foreach(Mutant mutant in mutants)
{
label12.Text += mutant.displayInfo() + "\n"; // This will create a seperate line for each displayInfo
// label12.Text += mutant.displayInfo(); //This will add them on the same line
}
|
Label control does not display in for loop c#
Date : March 29 2020, 07:55 AM
help you fix your problem I am new to programming world, kindly be gentle and my question is why the label control does not displaying file name one by one when it is called in for each loop. My task is to read the folder which contains more files I need to read the file name and display in the label control but it is not working well for me, it is simple for all but I am a beginner Why I don't know find how to find out the mistake? , Here is a sample code using the background worker process BackgroundWorker bw = new BackgroundWorker();
public Form1()
{
InitializeComponent();
bw.WorkerReportsProgress = true;
bw.DoWork += bw_DoWork;
bw.ProgressChanged += bw_ProgressChanged;
}
void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
label1.Text = "File Scanning --> " + e.UserState as string;
}
void bw_DoWork(object sender, DoWorkEventArgs e)
{
string imageloc = @"D:\Image";
string[] files = Directory.GetFiles(imageloc);
foreach (var item in files)
{
bw.ReportProgress(0, item);
Thread.Sleep(1000);
}
}
protected void button1_Click(object sender, EventArgs e)
{
if (!bw.IsBusy)
{
bw.RunWorkerAsync();
}
}
|
I want to display label text for particular record in for loop
Date : March 29 2020, 07:55 AM
it fixes the issue , Try this, this should work: <div *ngFor="let item of requests; index as ix">
ix: {{ix}} FirstName:<b>{{item.name}}</b>
<button (click)="HandleRequest(true, ix)">Accept</button>
<button (click)="HandleRequest(false, ix)">Decline</button>
<label>{{requesStatus[ix]}}</label>
<!-- or -->
<label>{{(isAccepted[ix]) ? 'accepted' : 'declined'}}</label>
</div>
// in class level declare this
requesStatus: string[] = [];
// or
isAccepted: boolean[] = [];
// function to set and use in template
HandleRequest(accepted, ix) {
this.requesStatus[ix] = (accepted) ? 'accepted' : 'declined';
// or
this.isAccepted[ix] = accepted;
}
|
How to display results in label in while(true) loop
Date : March 29 2020, 07:55 AM
|